Closed as not planned
Description
Describe the bug
During the migration from v4 to v5, queryOptions is inferred to have an exact return, but infiniteQueryOptions is inferred to have the data type unknown only. Why do we not have to specify the type directly in useInfiniteQuery, compared to the fact that we could have declared type only in queryOptions?
Your minimal, reproducible example
https://codesandbox.io/p/sandbox/inspiring-roman-gmkcf2?file=%2Fsrc%2FApp.js%3A4%2C1
Steps to reproduce
sandbox cant show my issue.
i attach my test code here
interface Post {
id: number;
title: string;
}
interface PostsResponse {
data: Post[];
nextCursor?: number;
}
export const postsInfiniteQuery = (limit = 10) =>
infiniteQueryOptions<PostsResponse, AxiosError>({
queryKey: ['posts', limit],
queryFn: async ({ pageParam = 0 }) => {
const res = await axios.get<PostsResponse>('/api/posts', {
params: { cursor: pageParam, limit },
});
return res;
},
initialPageParam: 0,
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
});
const useUnknown = () => {
const {
data,
fetchNextPage,
hasNextPage,
isFetchingNextPage,
isLoading,
isError,
} = useInfiniteQuery(postsInfiniteQuery(10));
}
Expected behavior
data return type as { pages: { data: Post[], nextCursor?:number }
How often does this bug happen?
Every time
Screenshots or Videos
Platform
macOS
Tanstack Query adapter
react-query
TanStack Query version
5.77.1
TypeScript version
5.8.2
Additional context
axios version: 1.7.9