You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This should produce a type error, since queryResult.data will contain a string, contrary to the declared type of number.
But it compiles cleanly with no type errors detected.
A type error will, however, be detected if a no-op selectFn is provided:
const queryResult: UseQueryResult<number> = useQuery({
queryKey: ['key'],
queryFn: async () => 'not a number',
select: (s) => s,
});
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
react-query
TanStack Query version
v5.40.1
TypeScript version
v5.2.2
Additional context
One possible avenue of attack might be to switch the template arguments to take the type of the select function instead, and try to infer TData from that. For example (where I've simplified to focus just on the types of interest):
if you know a good way to fix this, please make a PR including type tests. My general recommendation is to use type inference and not slap the UseQueryResult type on your custom hooks. It will also take away some optimizations we do with overloads.
Describe the bug
There is a problem with hidden typescript type errors in the
useQuery()
hook whenselect
is not defined.Your minimal, reproducible example
Simple 1-line example provided inline
Steps to reproduce
Try compiling the following:
Expected behavior
This should produce a type error, since
queryResult.data
will contain astring
, contrary to the declared type ofnumber
.But it compiles cleanly with no type errors detected.
A type error will, however, be detected if a
no-op
selectFn is provided:How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
react-query
TanStack Query version
v5.40.1
TypeScript version
v5.2.2
Additional context
One possible avenue of attack might be to switch the template arguments to take the type of the select function instead, and try to infer TData from that. For example (where I've simplified to focus just on the types of interest):
The text was updated successfully, but these errors were encountered: