T
TanStack•11mo ago
continuing-cyan

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
continuing-cyan
continuing-cyanOP•11mo 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?
deep-jade
deep-jade•11mo ago
I'll take a look today 👀
deep-jade
deep-jade•11mo ago
remove as const from line 42 to get the error
continuing-cyan
continuing-cyanOP•11mo ago
Thanks, this works! 🙂

Did you find this page helpful?