-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type Error when using useQueries
with results returning different types, generated from an array
#7974
Comments
different return types generally work, I think this is rather an issue with Or rather, a combination of the two:
So it seems the But even if we get rid of that by making our keys of type
This is again because inference of Thinking about it some more - I don't think variadic queries of different types is something that we can infer / support. For variadic queries, they have to be the same type. Static queries (tuples) of different types are supported. In your example, ideally the last element in the result array would be typed as bar, and all the others as foo. But I think this is way to complex to achieve, which is why we fallback to I think you have to do manual type annotations for this one. Like, what should the data type of |
I agree that typing this will be way too complex. To answer your question, I think that the type can be export const useThings = () => {
const foos = [1, 2, 3].map(() => ({ ...FooQueries.get() }));
return useQueries({
queries: [{ ...BarQueries.get() }, ...foos],
});
}; |
if you want to make that work, please take a stab at it. |
Describe the bug
I want to use
useQueries
to fetchx
queries every time, and anothery
queries, whose count is not known at compile time.Here is a short example (playground below):
There is a type error that says:
Your minimal, reproducible example
https://tsplay.dev/mq2d2W
Steps to reproduce
use
useQueries
with a variable count of queries that have different return type than other queriesExpected behavior
Expected to be able to pass an array of queries with variable length to
useQueries
, along with other queries with different return type.How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Tanstack Query adapter
None
TanStack Query version
5.52.1
TypeScript version
5.5.4
Additional context
Edit: I tinkered a bit more with this and it appears that the issue is with the
queryOptions
function. Here is the full error:Edit 2: If all queries return the same type of result, it works.
The text was updated successfully, but these errors were encountered: