Skip to content

fix: infer pageParam from computed queryFn with conditional skipToken#10335

Open
danieljayasurya-e wants to merge 4 commits intoTanStack:mainfrom
danieljayasurya-e:fix/pageParam-type
Open

fix: infer pageParam from computed queryFn with conditional skipToken#10335
danieljayasurya-e wants to merge 4 commits intoTanStack:mainfrom
danieljayasurya-e:fix/pageParam-type

Conversation

@danieljayasurya-e
Copy link
Copy Markdown

@danieljayasurya-e danieljayasurya-e commented Mar 25, 2026

🎯 Changes

This PR fixes a Vue Query type inference issue in useInfiniteQuery when queryFn is provided through a computed wrapper,
especially in conditional skipToken cases.

Previously, TypeScript could lose contextual typing for the computed queryFn, causing pageParam to fall back to unknown even when initialPageParam clearly established its type. This change makes the queryFn option preserve contextual typing in that shape by explicitly typing the property and widening the skipToken branch to a generic symbol for inference
purposes.

The PR also adds a regression type test covering computed(() => enabled ? ({ pageParam }) => ... : skipToken) to ensure
pageParam and lastPageParam remain strongly typed.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features
    • Improved TypeScript typing for useInfiniteQuery so query functions provided via computed/refs or skip tokens infer pageParam more accurately.
  • Tests
    • Added type-level tests validating inference for conditional query functions, skip-token scenarios, and numeric pageParam progression in getNextPageParam.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

Updated typings for useInfiniteQuery so queryFn accepts a MaybeRefOrGetter of QueryFunction or SkipToken; added a type-level test asserting pageParam infers as number when queryFn is a computed that conditionally returns a function or skipToken.

Changes

Cohort / File(s) Summary
Type System Change
packages/vue-query/src/useInfiniteQuery.ts
Replaced MaybeRefDeep<...['queryFn']> with `MaybeRefOrGetter<QueryFunction<...>
Type-Level Test Update
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx
Imported ref and skipToken and added a new type-only test verifying useInfiniteQuery infers pageParam as number when queryFn is a computed that conditionally returns a QueryFunction or skipToken.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble types where tokens skip,

Computeds hop and never slip,
Numbers page and onward bound,
Infinite queries dance around,
A rabbit's cheer for typings sound.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: improving type inference for pageParam in useInfiniteQuery when queryFn is a computed with conditional skipToken.
Description check ✅ Passed The description provides detailed context of the issue, explains the fix approach, mentions the regression test, and includes all required checklist items properly marked.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 3, 2026

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 2f5b733

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 1m 26s View ↗
nx run-many --target=build --exclude=examples/*... ❌ Failed 19s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-03 14:18:16 UTC

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/vue-query/src/useInfiniteQuery.ts (1)

56-69: Consider aligning useQuery and useInfiniteQuery queryFn option ergonomics.

UseInfiniteQueryOptions now supports getter-wrapped queryFn, but UseQueryOptions still handles all non-enabled properties through MaybeRefDeep (see packages/vue-query/src/useQuery.ts, Line 22-52). A follow-up alignment could reduce API surprise across Vue Query hooks.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/vue-query/src/useInfiniteQuery.ts` around lines 56 - 69, The
UseInfiniteQueryOptions typing in useInfiniteQuery.ts treats the queryFn
property as MaybeRefOrGetter but other options still use MaybeRefDeep, causing
inconsistency with useQuery; update the UseQueryOptions (in useQuery.ts) or
align useInfiniteQuery's generics so both hooks accept getter-wrapped queryFn
the same way: ensure the QueryOptions generic mapping uses MaybeRefOrGetter for
the 'queryFn' property (reference symbols: useInfiniteQuery,
UseInfiniteQueryOptions, queryFn, useQuery, UseQueryOptions, MaybeRefDeep,
MaybeRefOrGetter) so the two hooks have matching ergonomics for getter-wrapped
query functions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/vue-query/src/useInfiniteQuery.ts`:
- Around line 56-69: The UseInfiniteQueryOptions typing in useInfiniteQuery.ts
treats the queryFn property as MaybeRefOrGetter but other options still use
MaybeRefDeep, causing inconsistency with useQuery; update the UseQueryOptions
(in useQuery.ts) or align useInfiniteQuery's generics so both hooks accept
getter-wrapped queryFn the same way: ensure the QueryOptions generic mapping
uses MaybeRefOrGetter for the 'queryFn' property (reference symbols:
useInfiniteQuery, UseInfiniteQueryOptions, queryFn, useQuery, UseQueryOptions,
MaybeRefDeep, MaybeRefOrGetter) so the two hooks have matching ergonomics for
getter-wrapped query functions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 36c8c7bf-8625-49b3-a41d-ef16a4aa99e6

📥 Commits

Reviewing files that changed from the base of the PR and between 1f66441 and 2f5b733.

📒 Files selected for processing (1)
  • packages/vue-query/src/useInfiniteQuery.ts

@TkDodo
Copy link
Copy Markdown
Collaborator

TkDodo commented Apr 3, 2026

test are failing, seems related

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants