Description
Describe the bug
When passing options created with the queryOptions
helper to QueriesObserver
we got the following TypeScript error as it is unable to assign UseQueryOptions
to QueryObserverOptions
:
Type 'UseQueryOptions<string, Error, string, string[]> & { initialData?: undefined; } & { queryKey: DataTag<string[], string>; }' is not assignable to type 'QueryObserverOptions<unknown, Error, unknown, unknown, QueryKey, never>'.
Types of property 'refetchInterval' are incompatible.
Type 'number | false | ((query: Query<string, Error, string, string[]>) => number | false | undefined) | undefined' is not assignable to type 'number | false | ((query: Query<unknown, Error, unknown, QueryKey>) => number | false | undefined) | undefined'.
Type '(query: Query<string, Error, string, string[]>) => number | false | undefined' is not assignable to type 'number | false | ((query: Query<unknown, Error, unknown, QueryKey>) => number | false | undefined) | undefined'.
Type '(query: Query<string, Error, string, string[]>) => number | false | undefined' is not assignable to type '(query: Query<unknown, Error, unknown, QueryKey>) => number | false | undefined'.
Types of parameters 'query' and 'query' are incompatible.
Type 'Query<unknown, Error, unknown, QueryKey>' is not assignable to type 'Query<string, Error, string, string[]>'.
Types of property 'queryKey' are incompatible.
The type 'QueryKey' is 'readonly' and cannot be assigned to the mutable type 'string[]'.
Your minimal, reproducible example
Steps to reproduce
In the playground, see that QueryObserver
accepts testQuery
as options and that myFirstObserver
type is correctly inferred to QueryObserver<string, Error, string, string, string[]>
.
However QueriesObserver
errors when passing testQuery
as options. If we inline the object then we have no errors.
Also QueryObserverResult
is not properly inferred (TData
is always unknown
) even when passing the options as an inline object (I can open another issue for this point if needed).
No issue at runtime, the code is working as expected.
Expected behavior
We should be able to pass the result of the queryOptions
helper to QueriesObserver
and have QueryObserverResult
properly inferred.
Quoting the documentation on https://tanstack.com/query/latest/docs/reference/QueriesObserver#queriesobserver:
The options for the
QueriesObserver
are exactly the same as those of useQueries.
So, from what I understand, the queryOptions
helper here should work too (and as you can see in the playground above, it actually works with QueryObserver
, but not QueriesObserver
).
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- macOS
- Chrome 124
Tanstack Query adapter
react-query
TanStack Query version
v5.36.2
TypeScript version
v5.4.5
Additional context
No response