-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[Types] useMutation returning union undefined with new types? #810
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
Is this still a valid problem now #767 is merged? 🤔 |
I just installed it today so I think so? WIth:
My package.json: "react-query": "^2.5.7-tsnext.1", |
Hi @Buuntu, thanks for giving feedback on the new types! The type has indeed changed because the mutation returns |
Mutate does not throw by default unless throwOnError is true. The docs should be updated to reflect this. |
I suppose it's not doable to set a conditional type depending on what the config is? Something like: https://www.typescriptlang.org/docs/handbook/advanced-types.html#conditional-types. If not I'm happy to update the docs and submit a PR. |
Yes it is, I get the error on 2.5.11 but not on 2.5.7-tsnext.1 |
Looks like with the docs and the new 2.5.7-tsnext.1 types, we'll be in good shape. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Mutate now potentially returns an undefined type, which is different from the return type before I believe? Maybe that's the expected behavior but by looking at the docs you generally aren't checking that something is returned. Shouldn't it just throw an error rather than return undefined if something goes wrong?
So using the new types you now have to check that the data exists before using it.
Before
After:
There might be a good reason for this but it does deviate from the docs (https://react-query.tanstack.com/docs/guides/mutations#basic-mutations) and previous types.
The text was updated successfully, but these errors were encountered: