Skip to content
Source
Sign inSign up
TanStack/query

`select` type inference not working properly when spreading queryOptions in useQueries/useSuspenseQueries #9679

Send to my agent
Closedkangju2000(GitHub profile, opens in a new tab) opened this issue 1 comment

Describe 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

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgRwK4FMoE8DyYbAQB2AzgDRyonoCKG2FV6AylWOqbfVo9XZsHTlK1ViXad+UQSTgBfOADMoEEHADkAARgBDUroDGAawD0UdDoMwAtGkxZ1AbgBQr9AA9IsOAeIl4AMKqYHAAvHAAFACUYQB8iM5wcCYmcADmEBAAJok+fvCKmVJYYSJc9hEIuUkAdHWFEMV4BH7RZNVw1AA26FYAXHBZOrpxg8M6NTrtSXJRLrkpcABGOjlJvvpKmStQUjKlTHtClR120kIDANodSVVJ9-d1NQ1N+ISkbTf33b0wA0MjULxAETKZfOTTB7LHS7bjNd4kT5QuAdAC6kNm8ySiwy2VyG380KgYgkfG4B1EbA4ZIqd0edR2rxaHyikKSP36Y0BwPGNQMNSyGLmrmxqRWazymwaOxJ1PK51k4SYssk9BkJweZxkVy+dORTxecLerVZX3Z6B6nJBoxBkzZ9whurNcCejKNzMRpuR5stfy5OhtvIM9pm9vRuUxzjk8xgWHYcAAYpkAEpCSCcUp0nQDfzSIhpFxJJYDIioEBLTAuaOuAkFIruhGlaJxXJnXDGj56lDcADS6CwV3UAEZ1OHNdwE0QBs2gV8AAoqEDAag1cwkCBdABu6A13uzGhHIfuxbgQ6PChIw2Xin2SYgqfEfnQXvkwucsfjACEYQ-09RM-iAxdlkJZlhWUCFvIVbzLWRJMo24QzrErYNq0XZtn2A5wJc6gAEyjvabaTtOMSzsiC6qMu6CrkIG7bruyIGEBzpJCBcC4Ueobgp0V4kDeQhwN+UC-k+L6YkAA

Steps to reproduce

Steps to reproduce:

  1. Open this TypeScript Playground

  2. Compare type inference in useQuery vs useQueries:

    • useQuery with spread queryOptions → select parameter is correctly typed
    • useQueries with spread queryOptions → select parameter is unknown
  3. Same issue occurs with useSuspenseQuery (works) vs useSuspenseQueries (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

Sign in to join this conversation.