-
-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Description
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):
- ZenStack version: 3.4.1
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,
},
},
}
},
},
)Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels