useMutation - type errors with my mutation function #1216
Replies: 2 comments 1 reply
-
Hi @cliffordfajardo! It's quite possible you solved this by now, but for anyone else who might happen across this discussion thread, I wanted to share the realization I had when I ran into this! A export type MutationFunction<TResult, TVariables = unknown> = (
variables: TVariables
) => Promise<TResult> It's easy to miss that when the type gets collapsed to The way around this is pass the variables to the mutation as object, as it recommends in the docs (silly me forgot about this little important detail). So: const signin = ({ username, password}: {username: string, password: string}) => {
const AWSCognitoUser = await Auth.signIn({username,password}) as CognitoUser;
return AWSCognitoUser;
}
const [signin1] = useMutation(signin)
// Invoke later
const me = signin({username: "super-user", password: "password1234"}) Hope this might help! 🙂 |
Beta Was this translation helpful? Give feedback.
-
This is not emphasized enough in the docs @courier-new , that you have to give it only one argument |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey fellow react-query users,
I'm using Typescript with
react-query
and I'm getting type errors raised for the mutation function I'm passing intouseMutation
.This is the typescript error I'm receiving:
I created a super small codesanbox of my code. Two of the
useMutation
examples are throwing type errors but the 3rd one isn't (using a much simpler function)Any ideas on how to work around this? Any help is appreciated 😄

Code Sanbox Link
Beta Was this translation helpful? Give feedback.
All reactions