TanStackT
TanStack9mo ago
6 replies
worthy-azure

Type error when using `keepPreviousData()` with `useInfiniteQuery`

When setting up an infinite query that looks something like:

useInfiniteQuery({
    queryKey: ['...'],
    queryFn,
    enabled,
    retry,
    initialPageParam: 0,
    getNextPageParam,
    staleTime: 60_000, // 1 min
    initialData: keepPreviousData,
  });


there's a type error with initialData. The error looks like:

No overload matches this call.
  Overload 1 of 3, '(options: DefinedInitialDataInfiniteOptions<MyType, unknown, InfiniteData<MyType, unknown>, (string | string[] | undefined)[], number>, queryClient?: QueryClient | undefined): DefinedUseInfiniteQueryResult<...>', gave the following error.
    Type '<T>(previousData: T | undefined) => T | undefined' is not assignable to type '((InfiniteData<MyType, number> | InitialDataFunction<InfiniteData<MyType, number>>) & (InfiniteData<...> | (() => InfiniteData<...>))) | undefined'.
      Type '<T>(previousData: T | undefined) => T | undefined' is not assignable to type 'InfiniteData<MyType, number> & (() => InfiniteData<MyType, number>)'.
        Type '<T>(previousData: T | undefined) => T | undefined' is not assignable to type 'InfiniteData<MyType, number>'.
Was this page helpful?