Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(query-core): make
MutateFunction
optional undefinable-variables #8737New 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: main
Are you sure you want to change the base?
feat(query-core): make
MutateFunction
optional undefinable-variables #8737Changes from 1 commit
2ddfb1c
3085870
02db0f2
01b77b4
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
that’s a good improvement 👍 . I’m missing a test for the use-case where we have a mutation function that doesn’t take anything in, so the variables are
void
.Also, I’d prefer if we create the mutation functions not via type assertions, but by whatever a
MutationObserver
returns. Something like: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.
I've added the
void
case as requested. However, I couldn’t create a test usingMutationObserver
because themutate
function is implemented as a standalone function rather than usingMutateFunction
. As a result, the changes don’t impact its behavior. Let me know if you have any suggestions on how to approach testing this scenario.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.
oh interesting. question is if it would also work with the
mutate
function returned fromuseMutation
, as that is what most users will use. The type is defined here:query/packages/react-query/src/types.ts
Lines 197 to 204 in 3e3fba9
would be great to have a test in
useMutation.test-d.tsx
in the react-query adapter for this then 🙏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.
I've already covered this case. Please check my tests.
https://github.com/TanStack/query/pull/8737/files#diff-fd352cb3d35bea507f0ff667365ff9ab3c51a78c493656207dc3a5291a2491b2R67-R133
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.
yeah that’s okay for the
query-core
, but it doesn’t actually test whatuseMutation
in react-query does. It’s great that we cover the functionality that we have inuseMutation
now, but if we refactor that, it won’t be covered by the test in the core.That’s why each adapter should have its own tests for the types they are doing. But we can do this in a follow-up.