-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Closed
Copy link
Labels
Description
Describe the bug
It doesn't seem possible to pass an optional initialData parameter to infiniteQueryOptions, while it does work for useInfiniteQuery.
Example query not working:
Your minimal, reproducible example
Steps to reproduce
function useWrapper({ initialData }: { initialData?: { example: true } }) {
const queryOptions = infiniteQueryOptions({
queryKey: ["example"],
queryFn: async () => initialData,
// initialData below errors
initialData: initialData
? () => ({ pages: [initialData], pageParams: [] })
: undefined,
getNextPageParam: () => 1,
initialPageParam: 1,
});
}
Typescript error:
No overload matches this call.
Overload 1 of 2, '(options: DefinedInitialDataInfiniteOptions<{ example: true; } | undefined, Error, InfiniteData<{ example: true; } | undefined, unknown>, string[], number>): UseInfiniteQueryOptions<...> & ... 1 more ... & { ...; }', gave the following error.
Type '(() => { pages: { example: true; }[]; pageParams: never[]; }) | undefined' is not assignable to type '(InfiniteData<{ example: true; } | undefined, number> | InitialDataFunction<InfiniteData<{ example: true; } | undefined, number>> | undefined) & (InfiniteData<...> | (() => InfiniteData<...>))'.
Type 'undefined' is not assignable to type '(InfiniteData<{ example: true; } | undefined, number> | InitialDataFunction<InfiniteData<{ example: true; } | undefined, number>> | undefined) & (InfiniteData<...> | (() => InfiniteData<...>))'.
Overload 2 of 2, '(options: UndefinedInitialDataInfiniteOptions<{ example: true; } | undefined, Error, InfiniteData<{ example: true; } | undefined, unknown>, string[], number>): UseInfiniteQueryOptions<...> & ... 1 more ... & { ...; }', gave the following error.
Type '(() => { pages: { example: true; }[]; pageParams: never[]; }) | undefined' is not assignable to type 'undefined'.
Type '() => { pages: { example: true; }[]; pageParams: never[]; }' is not assignable to type 'undefined'.(2769)
Expected behavior
Equivalent example using useInfiniteQuery that works fine:
function useWrapperQuery({ initialData }: { initialData?: { example: true } }) {
return useInfiniteQuery({
queryKey: ["example"],
queryFn: async () => initialData,
initialData: initialData
? () => ({ pages: [initialData], pageParams: [] })
: undefined,
getNextPageParam: () => 1,
initialPageParam: 1,
});
}
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
N/A
Tanstack Query adapter
react-query
TanStack Query version
v5.59.0
TypeScript version
v5.6.2
Additional context
No response