useMutation types: variables are optional
See original GitHub issueDescribe the bug
in TypeScript, the mutation function created by the useMutation hook can always be called without passing arguments, because the type TVariables
is set to optional:
To Reproduce
I made a codeSandbox example: https://codesandbox.io/s/async-currying-wepni
Please look at the comment at line 54
I should be forced to call that function like this:
mutatePostTodo(text)
but I can also call it like this:
mutatePostTodo()
Expected behavior
The type of variables that you need to pass to that function should be equal to the type that the actual mutation function accepts, in other words, it should be variables: TVariables
rather than variables?: TVariables
Desktop (please complete the following information):
- OS: MacOS Catalina
- Browser: Chrome
- Version: 85
Additional context
All the usages of variables
in that function are accessed with the bang operator, for example:
So I don’t really see why it should be optional to begin with 🤷 .
Happy to make a PR if you approve of this 😃
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:13
The typing issue has been fixed in V3
I would be okay implementing this in v2 as non-breaking, but I’ll leave that up to @boschni since he knows more about the type implications. Otherwise, expect it in v3.