Description and expected behavior
When using useInfiniteFindMany in ZenStack, the lastPageParam (and allPageParams) parameter inside getNextPageParam is inferred as unknown.
In real-world infinite query scenarios, we typically reuse lastPageParam to construct the next query arguments (instead of rebuilding the entire args object manually). However, since lastPageParam is typed as unknown, this pattern becomes unsafe and requires as any casts.
Under the hood, TanStack Query’s useInfiniteQuery correctly infers TPageParam from initialPageParam. It appears that ZenStack’s wrapper does not properly forward the generic parameter, causing TPageParam to default to unknown.
Environment (please complete the following information):
Additional context
const PAGE_SIZE = 20
const query = zen.user.useInfiniteFindMany(
{
select: {
id: true,
name: true,
email: true,
createdAt: true,
},
where: {
isActive: true,
createdAt: {
gte: new Date('2024-01-01'),
},
},
orderBy: { createdAt: 'desc' },
take: PAGE_SIZE,
},
{
getNextPageParam: (lastPage, _allPages, lastPageParam: unknown) => {
if (lastPage.length < PAGE_SIZE) return undefined
const lastUser = lastPage[lastPage.length - 1]
// Common infinite-query pattern:
// Reuse previous args and only modify pagination condition
return {
...lastPageParam,
where: {
...lastPageParam.where,
id: {
lt: lastUser.id,
},
},
}
},
},
)
Description and expected behavior
When using
useInfiniteFindManyin ZenStack, thelastPageParam(andallPageParams) parameter insidegetNextPageParamis inferred asunknown.In real-world infinite query scenarios, we typically reuse
lastPageParamto construct the next query arguments (instead of rebuilding the entire args object manually). However, sincelastPageParamis typed asunknown, this pattern becomes unsafe and requiresas anycasts.Under the hood, TanStack Query’s
useInfiniteQuerycorrectly infersTPageParamfrominitialPageParam. It appears that ZenStack’s wrapper does not properly forward the generic parameter, causingTPageParamto default tounknown.Environment (please complete the following information):
Additional context