-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
useMutation callbacks context type depends on options object sorting #8988
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
Comments
Should you define type for it first? Like this
Then the type error will disappear |
Yes this does work and the error disappears. But the inference of |
In an object, type consumers must come after type producers. . microsoft/TypeScript#53018 (comment) We do have an eslint rule for |
Thanks for the clarification. An eslint rule would be a nice. |
I've created PR #9186 Could you take a look? :) |
Describe the bug
The type of
context
in theuseMutation
callbacks depends on the sorting of the options object.Your minimal, reproducible example
https://codesandbox.io/p/devbox/usemutationcontext-qsnk89
Steps to reproduce
src/index.tsx
or runtsc --noemit
context
in callbacks depends options object sortinguseMutation
works as intended, seconduseMutation
has type errorsExpected behavior
The type of
context
inuseMutation
callbacks should always be the same and not depend on the options object sorting.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Seems to be a types only bug. Has no effect on runtime values.
Tanstack Query adapter
react-query
TanStack Query version
5.72.2
TypeScript version
5.8.2
Additional context
No response
The text was updated successfully, but these errors were encountered: