Is there a way to infer the type of QueryKey? #1635
Replies: 5 comments 11 replies
-
|
It’s kinda hard to do with typescript. The preferred way would be inline functions, because you need to have access to |
Beta Was this translation helpful? Give feedback.
-
|
I'm using typescript: 3.9.7 and react-query 2.5.10. Looks like it was broken at some point. |
Beta Was this translation helpful? Give feedback.
-
|
I've found the broken version: 2.7.1 works, 2.8.0 doesn't |
Beta Was this translation helpful? Give feedback.
-
|
Think we should be able to infer the query key now because in V3 because the |
Beta Was this translation helpful? Give feedback.
-
|
Ive just installed react-query to replace useSWR on a query, and the fetching works so much better! But the types aren't being inferred here anymore. Is there something I need to do or is this just not being done as well in react-query? |
Beta Was this translation helpful? Give feedback.


Uh oh!
There was an error while loading. Please reload this page.
-
It looks like the type for QueryKey is
However, I feel like the typing can be narrowed down further than just
unknown[].Is there a way for react-query to automatically infer the type of my query key and have it passed it to the
QueryFunctionContext?For example:
I think I can just create my own type that extends from
QueryFunctionContext, but I would prefer that react-query infers the type for me so that I don't have to create my own type.Beta Was this translation helpful? Give feedback.
All reactions