Closed jaens closed 2 weeks ago
Actually, I guess I found a workaround: Changing all UseQueryOptions<>
to UseSuspenseQueryOptions<>
seems to make it work.
...since useQuery
can also take UseSuspenseQueryOptions<>
-- is that guaranteed?
What is the common supertype for both suspense and non-suspense query options?
Yeah, I think it was changed in this pr https://github.com/TanStack/query/pull/8082
Basically, suspense can't take a skipToken
but regular query can so they now have different options. UseSuspenseQueryOptions
is therefore narrower and can fit in useQuery
just fine.
yeah so passing queryOptions to useSuspenseQuery still works, but it fails if the queryFn is a skipToken.
If you build abstractions, you have to re-do what we do in our types; you can indeed just return SuspenseQueryOptions
and pass those to either useQuery
or useSuspsenseQuery
Describe the bug
In previous versions,
useSuspenseQuery
can take aUseQueryOptions<>
type as a parameter.After an upgrade, this no longer works, and instead throws a type error.
How is one supposed to declare the types of functions that return the return value of
queryOptions
?I looked into the current type declarations, and due to the heavy overloading now going on there, this actually seems impossible to do cleanly?
Your minimal, reproducible example
not sure how this is supposed to work, the issue template does not show how to import Tanstack Query into the TypeScript playground
Steps to reproduce
Expected behavior
No type error.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
TypeScript compiler
Tanstack Query adapter
React
TanStack Query version
5.59.20
TypeScript version
5.6.3
Additional context
No response