T
TanStack•14mo ago
correct-apricot

useQueries & queryOptions typing issue

Anyone else running into issue with code similar to:
const queries = [
getOptions1(
queryDetails[0],
question,
),
getOptions2(
queryDetails[1],
question,
),
];

const { data } = useQueries({
queries,
...


const getOptions1 = (
queryDetails: MyInterface,
question: string,
) => {
return queryOptions({
queryKey: ['source1', queryDetails, question],
queryFn: () =>
service.getDetails({
question,
}),
retry: false,
refetchOnWindowFocus: false,
});
};


const getOptions2 = (
queryDetails: MyInterface,
question: string,
) => {
return queryOptions({
queryKey: ['source2', queryDetails, question],
queryFn: () =>
anotherService.getDetails({
question,
}),
retry: false,
refetchOnWindowFocus: false,
});
};
const queries = [
getOptions1(
queryDetails[0],
question,
),
getOptions2(
queryDetails[1],
question,
),
];

const { data } = useQueries({
queries,
...


const getOptions1 = (
queryDetails: MyInterface,
question: string,
) => {
return queryOptions({
queryKey: ['source1', queryDetails, question],
queryFn: () =>
service.getDetails({
question,
}),
retry: false,
refetchOnWindowFocus: false,
});
};


const getOptions2 = (
queryDetails: MyInterface,
question: string,
) => {
return queryOptions({
queryKey: ['source2', queryDetails, question],
queryFn: () =>
anotherService.getDetails({
question,
}),
retry: false,
refetchOnWindowFocus: false,
});
};
I am getting: The type QueryKey is readonly and cannot be assigned to the mutable type When I only use the result of getOptions1 (single item in an array) or remove queryOptions it does work, not sure what I am doing wrong.
5 Replies
correct-apricot
correct-apricotOP•14mo ago
@TkDodo 🔮 I started using queryOptions after seing it being mentioned at https://ui.dev/c/query/avoiding-loading-states, have you ever seen this issue before?
fair-rose
fair-rose•14mo ago
I'll take a look today 👀
fair-rose
fair-rose•14mo ago
remove as const from line 42 to get the error
correct-apricot
correct-apricotOP•14mo ago
Thanks, this works! 🙂

Did you find this page helpful?