Replies: 5 comments
-
Not sure what you would want to add to the library. I think the types are technically correct because react-query cannot know what is in the cache, thus the type is |
Beta Was this translation helpful? Give feedback.
-
I guess I was just wanting it to be how Redux infers the No worries, I have just created a wrapper on my project for the |
Beta Was this translation helpful? Give feedback.
-
Seeing how this is not a bug per se, going to convert to a discussion. |
Beta Was this translation helpful? Give feedback.
-
I just had the same thought while using Not sure how easy to accomplish this is though. I'd require a setup up-front to tell the library what are the types for each key. Maybe the best solution for this is to just create a helper function that knows of that type, like @sshanzel mentioned. Curious if others also had the same thought, and what their solution for this was. |
Beta Was this translation helpful? Give feedback.
-
Hi @eddietex, I have the same thought about getQueryData. I implemented a solution on my project based on types override of the lib typings and I think it could be implemented in the lib easily. I opened a discussion on my suggestion, feel free to comment. #6105 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First, thank you for this wonderful library. Second, I'd love to contribute just let me know where I can start 🎉
Describe the
bugfeature requestCurrently, the
type
for thegetQueryData
can only be defined by a generic parameter. I think we can also use a generictype
that extends thetypeof
of a custom hook where we originally used thekey
which will infer theTResult
of theQueryResult
. So that we can also pass thetypeof
of a custom hook and the type will automatically be what is desired.I am fairly new with the library so please kindly inform me if I misunderstood the correct implementation.
To Reproduce

Steps to reproduce the behavior - this is how I use
react-query
:Then whenever I want to fetch the cached data which the

SAMPLE
key was used. I do this:In my humble opinion, I do feel that there is a greater margin for mistyping the actual definition of the desired custom hook when type inference is being utilized (like the example above with
useSample
hook. I am actually a victim of this problem as I didn't realize thegetQueryData
returns thedata
property already so I defined mygetQueryData
execution with theReturnType<typeof useSample>
without even checking the documentation of the actual returntype
).Expected behavior

I defined a type that infers the generic parameter which resulted to this:
Instead of returning the type
QueryResult
it inferred the type of thedata
property which I think is appropriate with the current case forgetQueryData
.Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
I can immediately request a PR if this is deemed appropriate 💯
Related Issue
Beta Was this translation helpful? Give feedback.
All reactions