-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Fix mutation hooks types #11024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Fix mutation hooks types #11024
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR modifies the type definitions for mutation hooks (useUpdate, useUpdateMany, useCreate, useDelete, useDeleteMany) by removing the Omit<UseMutationOptions, 'mutationFn'> wrapper, allowing mutationFn to be included in the options type.
Key changes:
- Type definitions now directly use
UseMutationOptionsinstead of omittingmutationFn - Applies consistently across all five mutation hooks
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ra-core/src/dataProvider/useUpdateMany.ts | Removed Omit<..., 'mutationFn'> wrapper from UseUpdateManyOptions type definition |
| packages/ra-core/src/dataProvider/useUpdate.ts | Removed Omit<..., 'mutationFn'> wrapper from UseUpdateOptions type definition |
| packages/ra-core/src/dataProvider/useDeleteMany.ts | Removed Omit<..., 'mutationFn'> wrapper from UseDeleteManyOptions type definition |
| packages/ra-core/src/dataProvider/useDelete.ts | Removed Omit<..., 'mutationFn'> wrapper from UseDeleteOptions type definition |
| packages/ra-core/src/dataProvider/useCreate.ts | Removed Omit<..., 'mutationFn'> wrapper from UseCreateOptions type definition |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| > = UseMutationOptions< | ||
| RecordType, | ||
| ErrorType, | ||
| Partial<UseUpdateMutateParams<RecordType>> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing mutationFn in the options type creates an inconsistent API. The type now accepts mutationFn, but the runtime implementation (line 113) will silently override any user-provided value since it's defined after ...mutationOptions is spread (line 110). This mismatch between the type system and runtime behavior could confuse API consumers. Consider either: (1) keeping the Omit<..., 'mutationFn'> to prevent users from passing it, or (2) restructuring the code to respect a user-provided mutationFn if that's the intended behavior.
| > = UseMutationOptions< | |
| RecordType, | |
| ErrorType, | |
| Partial<UseUpdateMutateParams<RecordType>> | |
| > = Omit< | |
| UseMutationOptions< | |
| RecordType, | |
| ErrorType, | |
| Partial<UseUpdateMutateParams<RecordType>> | |
| >, | |
| 'mutationFn' |
| > = UseMutationOptions< | ||
| Array<RecordType['id']>, | ||
| MutationError, | ||
| Partial<UseUpdateManyMutateParams<RecordType>> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing mutationFn in the options type creates an inconsistent API. The type now accepts mutationFn, but the runtime implementation (line 109) will silently override any user-provided value since it's defined after ...mutationOptions is spread (line 106). This mismatch between the type system and runtime behavior could confuse API consumers. Consider either: (1) keeping the Omit<..., 'mutationFn'> to prevent users from passing it, or (2) restructuring the code to respect a user-provided mutationFn if that's the intended behavior.
| > = UseMutationOptions< | |
| Array<RecordType['id']>, | |
| MutationError, | |
| Partial<UseUpdateManyMutateParams<RecordType>> | |
| > = Omit< | |
| UseMutationOptions< | |
| Array<RecordType['id']>, | |
| MutationError, | |
| Partial<UseUpdateManyMutateParams<RecordType>> | |
| >, | |
| 'mutationFn' |
| > = UseMutationOptions< | ||
| RecordType, | ||
| MutationError, | ||
| Partial<UseDeleteMutateParams<RecordType>> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing mutationFn in the options type creates an inconsistent API. The type now accepts mutationFn, but the runtime implementation will silently override any user-provided value since it's defined after ...mutationOptions is spread. This mismatch between the type system and runtime behavior could confuse API consumers. Consider either: (1) keeping the Omit<..., 'mutationFn'> to prevent users from passing it, or (2) restructuring the code to respect a user-provided mutationFn if that's the intended behavior.
| > = UseMutationOptions< | |
| RecordType, | |
| MutationError, | |
| Partial<UseDeleteMutateParams<RecordType>> | |
| > = Omit< | |
| UseMutationOptions< | |
| RecordType, | |
| MutationError, | |
| Partial<UseDeleteMutateParams<RecordType>> | |
| >, | |
| 'mutationFn' |
| > = UseMutationOptions< | ||
| Array<RecordType['id']> | undefined, | ||
| MutationError, | ||
| Partial<UseDeleteManyMutateParams<RecordType>> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing mutationFn in the options type creates an inconsistent API. The type now accepts mutationFn, but the runtime implementation will silently override any user-provided value since it's defined after ...mutationOptions is spread. This mismatch between the type system and runtime behavior could confuse API consumers. Consider either: (1) keeping the Omit<..., 'mutationFn'> to prevent users from passing it, or (2) restructuring the code to respect a user-provided mutationFn if that's the intended behavior.
| > = UseMutationOptions< | |
| Array<RecordType['id']> | undefined, | |
| MutationError, | |
| Partial<UseDeleteManyMutateParams<RecordType>> | |
| > = Omit< | |
| UseMutationOptions< | |
| Array<RecordType['id']> | undefined, | |
| MutationError, | |
| Partial<UseDeleteManyMutateParams<RecordType>> | |
| >, | |
| 'mutationFn' |
| > = UseMutationOptions< | ||
| ResultRecordType, | ||
| MutationError, | ||
| Partial<UseCreateMutateParams<RecordType>> |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing mutationFn in the options type creates an inconsistent API. The type now accepts mutationFn, but the runtime implementation (line 116) will silently override any user-provided value since it's defined after ...mutationOptions is spread (line 113). This mismatch between the type system and runtime behavior could confuse API consumers. Consider either: (1) keeping the Omit<..., 'mutationFn'> to prevent users from passing it, or (2) restructuring the code to respect a user-provided mutationFn if that's the intended behavior.
| > = UseMutationOptions< | |
| ResultRecordType, | |
| MutationError, | |
| Partial<UseCreateMutateParams<RecordType>> | |
| > = Omit< | |
| UseMutationOptions< | |
| ResultRecordType, | |
| MutationError, | |
| Partial<UseCreateMutateParams<RecordType>> | |
| >, | |
| 'mutationFn' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually Copilot is right! (for once...)
However attempting to fix the issue uncovered other TS issues that I was unable to solve so far.
We'll need more time to properly fix this PR.
Btw this PR should target master rather that next IMHO.
Problem
Our mutation hooks explicitly exclude the
mutationFnoption.However, we might want to override it to simplify hooks that reuse everything from a core mutation hook except the actual dataProvider call (ex:
useSoftDeletecould just pass a custom mutationFn touseDelete).Besides, the
mutationFnis optional in TanStack query so it won’t change anything for our users.Solution
Update the mutation hook to remove the explicit exclusion.