You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeScript error in mutate function from useMutation hook for variables param #2134
Expected behavior
Looks like type TVariables = void in UseMutateFunction is causing the issues. It should accept objects like in the example from docs https://react-query.tanstack.com/guides/mutations
^ it doesn’t work at all. if you checkout the error above. it's saying { password: string, email:string } is not assignable to void. it means the mutate function should not have param at all.
it is not defined what values should have for a type. The generic TVariables defaults to void and that's the error you are getting. If you write a function in typescript:
What should I pass as the first argument to mutate if the mutation doesn't take any variables?
functionuseLogout(){returnuseMutation(()=>api.logout());}constlogout=useLogout();logout.mutate(null,// neither null or {} is not assignable to parameter of type 'void'.{// ...options})
Activity
TkDodo commentedon Apr 16, 2021
you very likely need to type the input to the muateFn, otherwise, typescript has no way of knowing what it is:
YizhiHong commentedon May 12, 2021
^ it doesn’t work at all. if you checkout the error above. it's saying
{ password: string, email:string }is not assignable tovoid. it means the mutate function should not have param at all.TkDodo commentedon May 12, 2021
that is just because if you write:
it is not defined what
valuesshould have for a type. The genericTVariablesdefaults tovoidand that's the error you are getting. If you write a function in typescript:the compiler needs to know what
variableswill be, otherwise, it will be implicitly any.if you take my example where values has a type of
values: Variables, you will see that it works.SevenOutman commentedon Mar 5, 2022
What should I pass as the first argument to
mutateif the mutation doesn't take any variables?Update
Found that
void 0does the trick.