'Argument of type '{ name: string; email: string; password: string; }' is not assignable to parameter of type 'void'

I am using React Query with TypeScript.

Mutation:

   let mutation = useMutation((newUser) => {
      return signup(newUser)
   })

Submit function:

const onSignupSubmit = ({ name, email, password }: User) => {
      mutation.mutate(
          {
            name,
            email,
            password,
         }
      )
   }

Also this line giving me error:

mutation?.error?.response?.data?.field


Solution 1:[1]

you need to define the type of the mutation function passed to useMutation:

let mutation = useMutation((newUser: User) => {
    return signup(newUser)
})

a shorter way would be to omit the arrow function and just do:

let mutation = useMutation(signup)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TkDodo