-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Describe the bug
When using useQueries in React Query v5 with TypeScript, the select function’s input parameter data is inferred as unknown, even though the return type of queryFn should be known.
This leads to an unintuitive developer experience where data must be manually typed or casted, despite the fact that the shape of the data is already known via queryFn.
This does not happen in useQuery, which correctly infers the type of data passed to select.
Your minimal, reproducible example
Steps to reproduce
- Create a React component using
useQueries - Pass an array with a query using
queryFnthat returns an object - Add a
selectfunction like(data) => data.a - Hover
datain an IDE or let TypeScript check its type - Observe that
datais inferred asunknown
Expected behavior
I expected the data parameter in the select function to be inferred based on the return type of queryFn, just like it is in useQuery. This would enable proper autocomplete and type checking without requiring manual type assertions or annotations.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS 14.5
- IDE: VSCode
Tanstack Query adapter
None
TanStack Query version
v5.66.9
TypeScript version
5.2.2
Additional context
This issue breaks the type inference parity between useQuery and useQueries.
Similar issues have been raised in the past (#3994, #6556, #7270), but this problem remains in React Query v5 and may require a fresh look.
Even though the select function’s return type is inferred, the input data is not — likely because the UseQueryOptions<TQueryFnData, TError, TData> is defaulting to unknown when used in a dynamic array (useQueries).
A fix (or improved inference strategy) would significantly improve DX when using select with useQueries.