TanStackT
TanStack3y ago
8 replies
dual-salmon

useInfiniteQuery not inferring types

on typescript 5.3.2
on @tanstack/react-query@5.8.4

the following is not inferring the correct types for useInfiniteQuery result
  import { useInfiniteQuery } from '@tanstack/react-query';
  function Example () {
    const result = useInfiniteQuery({
        getNextPageParam: (lastPage, allPages, lastPageParam) => {
          return lastPageParam + 1;
        },
        initialPageParam: 0,
        queryFn: async ({ pageParam = 0 }): Promise<PersonApiResponse> => {
          return { data: [], page: pageParam, total: mockData.length } as PersonApiResponse;
        },
        queryKey: ['some-data'],
      });
  }


the type i get is
  const result: UseInfiniteQueryResult<InfiniteData<unknown, unknown>, Error>

does anyone know what's up?
- useQuery infers type correctly (e.g. if i only use queryFn/queryKey as above)
- @tanstack/react-query@4.x infers type correctly
- lowering versions @5.0 and @5.4 does not resolve my issue
- lowering typescript version to 4.9 does not resolve my issue
- made sure vscode is using same ts version as i have installed (rather than vscode version)
Was this page helpful?