`select` type inference not working properly when spreading queryOptions in useQueries/useSuspenseQueries #9679
Send to my agentDescribe the bug#
When using useQueries or useSuspenseQueries with spread queryOptions, the select function parameter type is not properly inferred. The data type needs to be explicitly defined, unlike when using useQuery with spread queryOptions where the type is correctly inferred automatically.
This appears to be related to #8708 and #8709, but the fix doesn't seem to fully address the type inference issue when spreading queryOptions within the queries array.
Your minimal, reproducible example#
Steps to reproduce#
Steps to reproduce:
Open this TypeScript Playground
Compare type inference in
useQueryvsuseQueries:useQuerywith spreadqueryOptions→selectparameter is correctly typeduseQuerieswith spreadqueryOptions→selectparameter isunknown
Same issue occurs with
useSuspenseQuery(works) vsuseSuspenseQueries(doesn't work)
Expected behavior#
The select function parameter should have its type automatically inferred from the queryFn return type, just like it does when using useQuery with spread queryOptions. Users shouldn't need to explicitly define the data type in the select function.
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
- OS: macOS
- Browser: Chrome
- Version: 140.0.7339.134
Tanstack Query adapter#
react-query
TanStack Query version#
v5.89.0
TypeScript version#
v5.2.2
Additional context#
No response
TkDodo closed this
TkDodo added labelsduplicate
Sign in to join this conversation.
this is a duplicate of:
and the workaround is the same - an additional wrapping in
queryOptions:https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgRwK4FMoE8DyYbAQB2AzgDRyonoCKG2FV6AylWOqbfVo9XZsHTlK1ViXad+UQSTgBfOADMoEEHADkAARgBDUroDGAawD0UdDoMwAtGkxZ1AbgBQr9AA9IsOAeIl4AMKqYHAAvHAAFACUYQB8iM5wcCYmcADmEBAAJok+fvCKmVJYYSJc9hEIuUkAdHWFEMV4BH7RZNVw1AA26FYAXHBZOrpxg8M6NTrtSXJRLrkpcABGOjlJvvpKmStQUjKlTHtClR120kIDANodSWe4+ISkJ0kvL3U1DU0PrVHTry-dXowAZDEaheKgiZTG7yX4wnZfFpPOH-OAdAC6f1m8ySiwy2VyG38yx0UDEEj43AOojYHEpFSqr3eCO4zUeJDaHUB-TGYIh4xqBhqWSxc1cuNSKzWeU2DR25Lp5XOsnCTAVknoMmeLzOMiuMLubNajNRcHen1Z32Rf1R3OBvJ0o0hkxtL1mrtulqRHJNqOZpMR7M5ps66B6PMhToFBg9sNdmNy2OccnmMCw7DgADFMgAlISQTilE06Ab+aRENIuJJLAZEVAgJaYFwp1xEgpFL3s0rROK5Q1Wn2nbgAaXQWCu6gAjOoE687pmiAMe+CYQAFFQgYDUGrmEgQLoAN3Q2tRJY009j1YGk9jChIwy3in22YgefEfnQKNhqfT6DgACFSTfAtqCLQkBl9QZa3rRsoCreRm3mNsSV2Ts-G7GIV09ewjSeSC7lHcc4EudQACYZ1dedF0iTDYjXDct3QHchH3I8T3+AwIJhV4sgGUjL3kW9OgfEgnyEACgPzD8v2xIA