TData
generic can be inferred or specified incorrectly, causing unexpected runtime errors.
#8639
Labels
TData
generic can be inferred or specified incorrectly, causing unexpected runtime errors.
#8639
Describe the bug
Related to #4770, revitalizing since
NoInfer
/overloads can at least partially help.TQueryFnData
is directly inferred fromqueryFn
specified in the hook optionsoptions
TData
defaults toTQueryFnData
, but can be specified via a generic or annotated return typeTData
generic is populated (by inference, or explicitly) , nothing enforces that there's type compatibility until you put aselect
function, leading to uncaught runtime breaks.Your minimal, reproducible example
https://codesandbox.io/p/devbox/vigilant-forest-7j45zd?file=%2Fsrc%2Findex.tsx%3A58%2C1
Steps to reproduce
See that
usePosts
andusePosts2
both have adata
type claiming to benumber
, but are instead aPost
at runtime.Examples:
Expected behavior
I expect to get a type-error, because I haven't specified a
select
function andTQueryFnData
does not equalTData
, therefore we have easy, uncaught runtime breaks.Potential solutions:
NoInfer
on theUseQueryResult<NoInfer<TData>, TError>
, will at least preventusePost2
issueselect
specified.How often does this bug happen?
None
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
None
TanStack Query version
5.66.0
TypeScript version
5.7.2
Additional context
No response
The text was updated successfully, but these errors were encountered: