onMutate return context type is unknown. #6483
-
I'm using the onMutate function and returning a context from the function however, when I try to use the returned context in the onSuccess or onError callback, the context type is being inferred as unknown. I tried setting a type on the onMutate handler but that didn't help and the only workaround I could do was to set the context as any in both the onSuccess and onError handlers. Is there a better way I could type the context? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
show a typescript playground please because that should work out of the box if you use type inference. |
Beta Was this translation helpful? Give feedback.
-
I tried to do that now and it's inferring the type correctly. I read your article on using typescript with react query and found out it's the generics in my mutation that are causing the issue. I know now to let typescript infer the type unless absolutely necessary. |
Beta Was this translation helpful? Give feedback.
-
I have the same question. I have a custom hook from the backend that is provided to me that uses
error: 'context' is of type 'unknown' The custom hook is not configured to accept generics. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
I get |
Beta Was this translation helpful? Give feedback.
I tried to do that now and it's inferring the type correctly. I read your article on using typescript with react query and found out it's the generics in my mutation that are causing the issue. I know now to let typescript infer the type unless absolutely necessary.