test({react,preact}-query): add type tests for 'useMutation'#10482
test({react,preact}-query): add type tests for 'useMutation'#10482
Conversation
📝 WalkthroughWalkthroughAdded two new TypeScript declaration test files that validate compile-time type inference and callback typings for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
View your CI Pipeline Execution ↗ for commit eae84f4
☁️ Nx Cloud last updated this comment at |
🚀 Changeset Version PreviewNo changeset entries found. Merging this PR will not cause a version bump for any packages. |
size-limit report 📦
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/react-query/src/__tests__/useMutation.test-d.tsx (1)
82-89: Optional cleanup: deduplicateCustomErrortest type.
CustomErroris declared twice; extracting one shared declaration will reduce repetition.♻️ Proposed refactor
describe('useMutation', () => { + class CustomError extends Error { + code: number + constructor(code: number) { + super() + this.code = code + } + } + it('should infer custom TError type', () => { - class CustomError extends Error { - code: number - constructor(code: number) { - super() - this.code = code - } - } - const mutation = useMutation<string, CustomError>({ mutationFn: () => Promise.resolve('data'), }) @@ it('should infer custom TError in onError callback', () => { - class CustomError extends Error { - code: number - constructor(code: number) { - super() - this.code = code - } - } - useMutation<string, CustomError>({ mutationFn: () => Promise.resolve('data'), onError: (error) => {Also applies to: 109-116
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/react-query/src/__tests__/useMutation.test-d.tsx` around lines 82 - 89, Tests duplicate the CustomError class declaration in two places (lines around the tests starting with "should infer custom TError type"); refactor by extracting a single shared CustomError declaration (class CustomError extends Error { code: number; constructor(code: number) { super(); this.code = code } }) into the shared scope of the test file (e.g., top of the describe or module-level) and remove the duplicated declaration in both test blocks so both tests reuse the same CustomError symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/react-query/src/__tests__/useMutation.test-d.tsx`:
- Around line 82-89: Tests duplicate the CustomError class declaration in two
places (lines around the tests starting with "should infer custom TError type");
refactor by extracting a single shared CustomError declaration (class
CustomError extends Error { code: number; constructor(code: number) { super();
this.code = code } }) into the shared scope of the test file (e.g., top of the
describe or module-level) and remove the duplicated declaration in both test
blocks so both tests reuse the same CustomError symbol.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e9e8ba61-2262-472d-94ad-7e87e4256d52
📒 Files selected for processing (1)
packages/react-query/src/__tests__/useMutation.test-d.tsx
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/preact-query/src/__tests__/useMutation.test-d.tsx (1)
83-89: Optional: deduplicateCustomErrorfixture used in two tests.
CustomErroris declared twice (Line 83 and Line 110). Extracting it once atdescribescope reduces duplication/drift.♻️ Proposed refactor
describe('useMutation', () => { + class CustomError extends Error { + code: number + constructor(code: number) { + super() + this.code = code + } + } + it('should infer custom TError type', () => { - class CustomError extends Error { - code: number - constructor(code: number) { - super() - this.code = code - } - } - const mutation = useMutation<string, CustomError>({ mutationFn: () => Promise.resolve('data'), }) @@ it('should infer custom TError in onError callback', () => { - class CustomError extends Error { - code: number - constructor(code: number) { - super() - this.code = code - } - } - useMutation<string, CustomError>({ mutationFn: () => Promise.resolve('data'), onError: (error) => {Also applies to: 110-116
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/preact-query/src/__tests__/useMutation.test-d.tsx` around lines 83 - 89, CustomError is duplicated in two test blocks; hoist the class declaration into the surrounding describe scope so both tests reuse the same fixture: remove the duplicate class at the later location and place a single declaration for class CustomError extends Error { code: number; constructor(code: number) { super(); this.code = code } } at the top of the describe that contains these tests, ensuring both tests reference the same CustomError symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/preact-query/src/__tests__/useMutation.test-d.tsx`:
- Around line 83-89: CustomError is duplicated in two test blocks; hoist the
class declaration into the surrounding describe scope so both tests reuse the
same fixture: remove the duplicate class at the later location and place a
single declaration for class CustomError extends Error { code: number;
constructor(code: number) { super(); this.code = code } } at the top of the
describe that contains these tests, ensuring both tests reference the same
CustomError symbol.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 89f11651-7a93-45bb-872f-9e70c566fd3e
📒 Files selected for processing (1)
packages/preact-query/src/__tests__/useMutation.test-d.tsx
🎯 Changes
useMutationin bothreact-queryandpreact-query(identical signatures), covering all 4 generic parameters:TData: inference frommutationFnreturn type, explicit genericTError: defaultDefaultError, custom error type,onError/onSettledcallbacksTVariables: inference frommutationFnparameter, defaultvoidTOnMutateResult: inference fromonMutatereturn type,onSuccess/onErrorcallbacksUseMutationResult,mutate,mutateAsyncqueryClientas optional second argument✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit