How can i assure to typescript the argument type of useMutation ?
I have this function that mutate
posts
When i call const { mutate } = useMutatePost("create");, i want to assure typescript that the mutate argument will be the type CreatePost.
But typescript is saying that Argument of type 'CreatePost' is not assignable to parameter of type 'CreatePost & MutationPayload'.3 Replies
adverse-sapphire•3y ago
This would need overloads or conditional return types. Why not make two custom hooks?
wise-white•3y ago
I second TkDodo, split to custom hooks. does react allow the use of hooks this way anyway? isn't it like putting them behind
if?other-emeraldOP•3y ago
I wasn't sure if this was a bad practice. I was just trying to make the code more concise
I'll split it, thanks guyts