Replies: 2 comments
-
Working version: Version with type error: |
Beta Was this translation helpful? Give feedback.
-
I think you are just providing the wrong types to - useMutation<Response, AxiosError, Response>
+ useMutation<Response, AxiosError, string, () => void>
not that I know of. There is no correlation on type level what is in a queryCache, as you can put anything in there. I was once working on a typesafe factory function that takes care of this, but never went very far because adding the generics to getQueryData / setQueryData is not much of an issue for us (if you keep all usages scoped to a custom hook for example). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
useMutation
hook with TypeScript. I took example from documentation:https://react-query.tanstack.com/docs/guides/optimistic-updates
I noticed that when typing it return value expects to be
Promise<TSnapshot> | TSnapshot
.Example that is provided returns
void
, which throws error when typechecking.What is the best approach to fix it?
Should I just move
setQueryData
to onError like it is done in examples page?https://react-query.tanstack.com/docs/examples/optimistic-updates
Or provide custom return type instead of using the one defined in type?
Or maybe it is a bug that should be fixed by updating types?
Also is there an easier way to get correct typing in
getQueryData
andsetQueryData
without need to specify type on every call?Beta Was this translation helpful? Give feedback.
All reactions