-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Typescript - useMutation variables can't handle unions #710
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
I bumped into the same issue. And it is a feature of typescript which is called Distributive conditional types. With current implementation it means that for mutation function with And wrapping conditional type into 1-tuple (convert I'd be happy to raise a PR with this change, but if I get contribution guide correctly I should be assigned to this issue first, or...? |
Thanks for looking into it. There's an open pull request to completely move the project to typescript. Might be worth waiting for that. #767 |
Is this still a valid problem now #767 is merged? 🤔 |
Seems to be working correctly now when using the example in the React Query tests |
The code above produces this Typescript error:
Argument of type '{ a: string; }' is not assignable to parameter of type '{ a: string; } & { b: string; }'. Property 'b' is missing in type '{ a: string; }' but required in type '{ b: string; }'.
I have no idea why the expected type becomes the intersection
{ a: string; } & { b: string; }
rather than the union I specified.The type definition for MutateFunction is:
changing
TVariables extends undefined
to[TVariables] extends [undefined]
seems to fix the problem. I don't understand why though.I'm using version 2.4.13
The text was updated successfully, but these errors were encountered: