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
Indexing a query factory with a union type (UserType = "company" | "club" | "player" | "supporter") causes TypeScript type mismatches in useQuery, ensureQueryData, getQueryData, and so on. The issue arises because entityProfileQueries[userType] returns a union of query options with distinct queryKey types (e.g., { userType: "player" } vs. { userType: "supporter" }), while these utilities expect a single type.
The player and supporter queries share ServerPlayerResponse and a select function, but the error occurs for all UserType values due to the queryKey union.
Noting that userType - player and supporter, share exactly the same TQueryFnData and TData from the select option, but queryKey differ by { userType: "player" } vs. { userType: "supporter" }
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: all
browser: all
version: latest
Tanstack Query adapter
react-query
TanStack Query version
latest
TypeScript version
latest
Additional context
Affects useQuery, ensureQueryData, getQueryData, and so on.
The text was updated successfully, but these errors were encountered:
Describe the bug
Indexing a query factory with a union type (
UserType = "company" | "club" | "player" | "supporter"
) causes TypeScript type mismatches in useQuery, ensureQueryData, getQueryData, and so on. The issue arises becauseentityProfileQueries[userType]
returns a union of query options with distinct queryKey types (e.g.,{ userType: "player" }
vs.{ userType: "supporter" }
), while these utilities expect a single type.The player and supporter queries share
ServerPlayerResponse
and a select function, but the error occurs for allUserType
values due to the queryKey union.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-yzi9yarp?file=src%2Floader.ts
Steps to reproduce
In the MRE, the error arises from this line in
src/loader.ts
:queryOptions
is underlined with an error, andtypeof data
is incorrectly resolving toServerPlayerResponse
.Expected behavior
The returned data from
queryClient.ensureQueryData(queryOptions)
should be a union of:Noting that userType -
player
andsupporter
, share exactly the sameTQueryFnData
andTData
from theselect
option, but queryKey differ by{ userType: "player" }
vs.{ userType: "supporter" }
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
react-query
TanStack Query version
latest
TypeScript version
latest
Additional context
Affects useQuery, ensureQueryData, getQueryData, and so on.
The text was updated successfully, but these errors were encountered: