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
I’ve put this in a typescript playground and it works fine if you remove the type annotations and let inference do its thing. You also had a type error in
getNextPageParambecause you returnedresbut probably meantres.data:https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAb2AOwGYuDApgRQK5ZQCeA8mDMBMgM4A0ce1WAkmhtvoUQL5ypQQQcAOQABGAEMakgMYBrAPRQsEmTAC0ARwLFhAWABQoSLDgSAHpTqI4MImCxwAgpYjUAolAFQ4vfoJELK30DQxRsKFRVRwAFN3gEQzg4YAATAC44ZDwQACNCAG4k20wAGyxM6hgoFABzIoNuQzDkCKiZWPjqACUsakgaR0SDZNSJSUy4qoBtAF0G5OQscxgAYTwoamgAfkzsvMLDJtCDZZN4GSoquEgq6lZ0ZExcHSI4AF44AApS0EwPuAARgADABKD4APmKKEez04xDIFCuX2GyWS2i4AGksERMtNhLcYNRhPRfiBMLNaMV0a8AGLITISahEZAyb4IG4SWpYGISKASISfYG+cHvCGIaloy7SODKagAiQAdwk-yCbgAdNyYAAeKZE3r9K5YCFfYQKCRgYAKQnE+iotEOsB8gXUTIcmQbLZQTJO7m8-kgUl-eDcKkjB0ihYR5QwDbIWV9dVjSRR5KhyXsYASUq8v3OkCZYFhh1agByyxguZ5+cyPyZla5WFF4tK9ar6qWK3Wm2gcG22wYyFSWEeWFSxcjzQM0uujCwAFVkHJkBBFfHPl9mxKTskZwlJcmJBPkqgsDAZAALcsrKvHuAXpnXhvcu-Aai0s+XupP28Z6gAGQgCRUjqV8PC8aAJ14T45wedgXi4L4bTgp4OFeL4QVBUEGmKPdOW5eVPkPbZ1V9PpigUBQHQAPW2I5DCAA