-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(query-core): fix context type error in onSuccess
#6355
fix(query-core): fix context type error in onSuccess
#6355
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 39d092d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution
Sent with 💌 from NxCloud. |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d66b7a8:
|
hm, I think the types are the way they are on purpose. That is, of course, if you have so, by setting generics manually with:
you're basically setting |
My apologies for missing some details. If you set it up this way on const { mutate } = useMutation<Data, Variables, Context>({
mutationFn: () => fetch('url'), // POST API
onSuccess(data, variables, context) {
// Here, the `context` type is `Context | undefined`
}
})
mutate(data, {
onSuccess(data, variables, context) {
// 'context' is `undefined`, but the type is `Context`
}
} Shouldn't both |
you're right, but I think |
Got it! I've learned a lot from your explanation. I'll adjust the type of Thanks a bunch for your patient clarification! |
…when `TContext` is defined
@TkDodo Pardon me! Is there anything else that needs to be adjusted in this PR? |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit d66b7a8. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Codecov ReportAttention:
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #6355 +/- ##
=========================================
+ Coverage 0 88.34% +88.34%
=========================================
Files 0 75 +75
Lines 0 2592 +2592
Branches 0 684 +684
=========================================
+ Hits 0 2290 +2290
- Misses 0 257 +257
- Partials 0 45 +45 ☔ View full report in Codecov by Sentry. |
Description:
When defining types in our code, it seems that the type on
onSuccess
formutate
is different from the one onuseMutation
:Perhaps there should be consistent type definitions here:
query/packages/query-core/src/types.ts
Line 699 in 3f82dc8
I've also made adjustments to the documentation.