Rename query data generics from TData to TQueryFnData for consistency
Hey! Thank you for react-query. It makes my job a lot easier.
Recently we ran into some confusion about the expected return value from getQueryData. The existing return type is called TData:
https://github.com/tannerlinsley/react-query/blob/fc4671f0731d1dd757f9fd037fd8e6755b3393d1/src/core/queryClient.ts#L105-L110
However, looking at the type for UseQueryOptions, TData refers to the value after the select function has been applied. The type that's returned from getQueryData is called TQueryFnData in this context.
https://github.com/tannerlinsley/react-query/blob/fc4671f0731d1dd757f9fd037fd8e6755b3393d1/src/react/types.ts#L26-L31
This PR presents no changes in functionality, but it aligns the generics names between UseQueryOptions and getQueryData! Now when working with UseQueryOptions, the names will help indicate the value returned from getQueryData.
To illustrate further, you might write code like this if you're expecting getQueryData to return TData, but the types here are incorrect!
type QueryOptions = UseQueryOptions<A, B, C>
type ExtractTData<P> = P extends UseQueryOptions<any, any, infer TData> ? TData : never;
type TData = ExtractTData<QueryOptions>
// ...
// `value` is not actually of type `TData`!
const value = queryClient.getQueryData<TData>(queryKey)
This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.
π Inspect: https://vercel.com/tanstack/react-query/CoB3uuo9f9eoc3nR1DHbi4g4jykr
β
Preview: https://react-query-git-fork-mattbrandlysonos-brandly-patch-1-tanstack.vercel.app
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Latest deployment of this branch, based on commit 258efb462d958421f876a279cfd481a4b32ced92:
| Sandbox | Source |
|---|---|
| tannerlinsley/react-query: basic | Configuration |
| tannerlinsley/react-query: basic-typescript | Configuration |
yeah, I think I'm fine with the change :)
Codecov Report
Merging #3451 (258efb4) into master (ba09e16) will not change coverage. The diff coverage is
100.00%.
@@ Coverage Diff @@
## master #3451 +/- ##
=======================================
Coverage 96.41% 96.41%
=======================================
Files 45 45
Lines 2286 2286
Branches 642 642
=======================================
Hits 2204 2204
Misses 79 79
Partials 3 3
| Impacted Files | Coverage Ξ | |
|---|---|---|
| src/core/queryClient.ts | 100.00% <100.00%> (ΓΈ) |
Continue to review full report at Codecov.
Legend - Click here to learn more
Ξ = absolute <relative> (impact),ΓΈ = not affected,? = missing dataPowered by Codecov. Last update ba09e16...258efb4. Read the comment docs.
Any updates regarding my comments here? Also, there are conflicts now.
FYI, I will close stale PRs somewhen next week. Please either address the open comments / resolve the merge conflicts or this PR will be closed. Thanks π
If you end up closing this I can take the current work and resolve your comments.
@SammRosenthal yes please go ahead and create a new PR, thank you π