Describe the bug
In the lit-query package, infiniteQueryOptions does not have the DataTag enrichment for the queryKey.
This leads to missing queryFn types when using setQueryData.
In the example, when hovering over querySlugType you can see the queryFn types injected with [dataTagSymbol]. Those are missing on infiniteQuerySlugType.
Checking the infiniteQueryOptions.ts, it is easy to see that the queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError> part is missing.
Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-mh2mvfum?file=src%2Fquery.ts
Steps to reproduce
- Define an example
exampleInfiniteQueryOptions with infiniteQueryOptions that has a queryKey and queryFn.
export const exampleInfiniteQueryOptions = (slug: string) => {
return infiniteQueryOptions({
queryKey: ['website', slug],
queryFn: async ({pageParam}) => {
const response = await fetch(`https://example.com/${slug}?cursor=${pageParam}`);
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<{previous: number, next: number, data: string}>;
},
initialPageParam: 0,
getPreviousPageParam: (firstPage) => firstPage.previous,
getNextPageParam: (lastPage) => lastPage.next,
})
}
- Use the defined
exampleInfiniteQueryOptions().queryKey in setQueryData
queryClient.setQueryData(infiniteQuerySlugType, (old) => {return {previous: 1, next: 3, data: [...old.data, 'queryOptions2']};});
- typescript complains about the old.data
unknown type
Expected behavior
- Define an example
exampleInfiniteQueryOptions with infiniteQueryOptions that has a queryKey and queryFn.
export const exampleInfiniteQueryOptions = (slug: string) => {
return infiniteQueryOptions({
queryKey: ['website', slug],
queryFn: async ({pageParam}) => {
const response = await fetch(`https://example.com/${slug}?cursor=${pageParam}`);
if (!response.ok) {
throw new Error(response.statusText);
}
return response.json() as Promise<{previous: number, next: number, data: string}>;
},
initialPageParam: 0,
getPreviousPageParam: (firstPage) => firstPage.previous,
getNextPageParam: (lastPage) => lastPage.next,
})
}
- Use the defined
exampleInfiniteQueryOptions().queryKey in setQueryData
queryClient.setQueryData(infiniteQuerySlugType, (old) => {return {previous: 1, next: 3, data: [...old.data, 'queryOptions2']};});
- typescript correctly infers about the old.data type
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Platform and browser agnostic, typescript issue
Tanstack Query adapter
None
TanStack Query version
0.2.11
TypeScript version
6.0.2
Additional context
lit-query does not yet exist as the option for Tanstack Query adapter field in bug report
Describe the bug
In the lit-query package, infiniteQueryOptions does not have the DataTag enrichment for the queryKey.
This leads to missing queryFn types when using setQueryData.
In the example, when hovering over
querySlugTypeyou can see the queryFn types injected with[dataTagSymbol]. Those are missing oninfiniteQuerySlugType.Checking the
infiniteQueryOptions.ts, it is easy to see that thequeryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>part is missing.Your minimal, reproducible example
https://stackblitz.com/edit/vitejs-vite-mh2mvfum?file=src%2Fquery.ts
Steps to reproduce
exampleInfiniteQueryOptionswithinfiniteQueryOptionsthat has a queryKey and queryFn.exampleInfiniteQueryOptions().queryKeyinsetQueryDataunknowntypeExpected behavior
exampleInfiniteQueryOptionswithinfiniteQueryOptionsthat has a queryKey and queryFn.exampleInfiniteQueryOptions().queryKeyinsetQueryDataHow often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Platform and browser agnostic, typescript issue
Tanstack Query adapter
None
TanStack Query version
0.2.11
TypeScript version
6.0.2
Additional context
lit-query does not yet exist as the option for Tanstack Query adapter field in bug report