Closed jijiseong closed 1 week ago
When Defining getNextPageParam Before queryFn in useInfiniteQuery (same issue with infiniteQueryOptions) lastPage is inffered as unknown
lastPage
It works well
useInfiniteQuery({ queryKey: ["data"], initialPageParam: 1, queryFn: ({ pageParam }) => getData(pageParam), getNextPageParam: (lastPage) => lastPage.hasNext ? lastPage.page + 1 : undefined, });
It doesn’t work well. lastPage in getNextPageParam is inffered as unknown
useInfiniteQuery({ queryKey: ["data"], initialPageParam: 1, getNextPageParam: (lastPage) => lastPage.hasNext ? lastPage.page + 1 : undefined, queryFn: ({ pageParam }) => getData(pageParam), });
https://codesandbox.io/p/devbox/dkhrfg
I expect that lastPage is inferred as the return type of getData.
None
No response
not affect
latest
v5.6.3
This is a known issue because of how TypeScript currently infers types. We have a lint rule that should catch this:
https://tanstack.com/query/v5/docs/eslint/infinite-query-property-order
Describe the bug
When Defining getNextPageParam Before queryFn in useInfiniteQuery (same issue with infiniteQueryOptions)
lastPage
is inffered as unknownIt works well
It doesn’t work well. lastPage in getNextPageParam is inffered as unknown
Your minimal, reproducible example
https://codesandbox.io/p/devbox/dkhrfg
Steps to reproduce
Expected behavior
I expect that lastPage is inferred as the return type of getData.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
not affect
Tanstack Query adapter
None
TanStack Query version
latest
TypeScript version
v5.6.3
Additional context
No response