Skip to content
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

useMutation expects incorrect mutateOptions as argument on mutate #661

Closed
basslagter opened this issue Jun 29, 2020 · 8 comments · Fixed by #674
Closed

useMutation expects incorrect mutateOptions as argument on mutate #661

basslagter opened this issue Jun 29, 2020 · 8 comments · Fixed by #674
Labels

Comments

@basslagter
Copy link

basslagter commented Jun 29, 2020

Describe the bug
Typescript complains about the argument I provide to my mutate function. This is since upgrade to the 2.4.4 version today

To Reproduce

 const [remove, { status }] = useMutation(removeSomething, {
    onSuccess: () => {},
    onError: () => {},
  });

When I call the mutate method like so:
remove('someId');

I get 'Type string has no properties in common with type 'MutateOptions''

The removeSomething function looks like:

export async function removeSomething(idToRemove: string): Promise<void> {
  // fetch
}
@Habbeunik
Copy link

Can you please specify the exact version, I just tested with 2.4.4 and I don't seem to have anything error

@basslagter
Copy link
Author

Update above. It's version 2.4.4 with typescript 2.9.5.
I use it with a NextJs app (9.4.4) if that might be of any influence.

@bespokebob
Copy link

This is happening to me too. I think it is due to https://github.com/tannerlinsley/react-query/blob/b3e4dda9fd80ec6f0ade49034ae6eeafe2055942/types/index.d.ts#L446 - if strictNullChecks is off, then undefined extends everything. Patching locally to reverse this (TVariables extends undefined) fixes it for me, though I'm not sure if that's actually the correct fix or not.

@basslagter
Copy link
Author

2.4.5 doesn't fix it either

@jelteliekens
Copy link
Contributor

@youngbob What you're saying is correct. It is best to reverse it so that TVariables extends undefined and not the other way arround. I created a pull request for it.

@basslagter
Copy link
Author

basslagter commented Jun 30, 2020

With 2.4.6 it's still not fixed for me.
I now see the message like 'Type 'string' has no properties in common with type 'MutateOptions<void, string, Error, unknown>'

@lee-reinhardt
Copy link

I don't think the fix was included in 2.4.6:
https://github.com/tannerlinsley/react-query/blob/v2.4.6/types/index.d.ts#L447

@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 2.4.7 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants