Skip to content

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

Open
danieljayasurya-e wants to merge 1 commit intoTanStack:mainfrom
danieljayasurya-e:fix/pageParam-type
Open

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

Conversation

@danieljayasurya-e
Copy link

@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
    • Enhanced type inference for useInfiniteQuery to properly support conditional query functions with skip tokens in computed properties.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ee71031e-c8fe-4184-a113-85673b72031d

📥 Commits

Reviewing files that changed from the base of the PR and between 1047cdc and 00af50a.

📒 Files selected for processing (2)
  • packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx
  • packages/vue-query/src/useInfiniteQuery.ts

📝 Walkthrough

Walkthrough

Enhanced type inference for useInfiniteQuery to support conditional skipToken expressions in computed properties. Added internal SkipTokenForUseInfiniteQuery type and corresponding type-level test case to ensure proper pageParam typing when query functions are conditionally returned.

Changes

Cohort / File(s) Summary
Type System Enhancement
packages/vue-query/src/useInfiniteQuery.ts
Added SkipTokenForUseInfiniteQuery internal type alias and updated UseInfiniteQueryOptions type definition to properly handle queryFn as MaybeRefOrGetter<QueryFunction | SkipTokenForUseInfiniteQuery> for improved type inference in computed expressions.
Type-Level Test
packages/vue-query/src/__tests__/useInfiniteQuery.test-d.tsx
Added imports for ref and skipToken, plus new type test verifying that useInfiniteQuery correctly infers pageParam as number when queryFn is a computed that conditionally returns either a function or skipToken.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A conditional hop, a token to skip,
Types now dance with each recursive flip,
PageParam flows pure as morning dew,
Infinite queries, now typed right and true!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: fixing type inference for pageParam in useInfiniteQuery when queryFn is a computed with conditional skipToken.
Description check ✅ Passed The description thoroughly explains the issue, the solution approach, includes completed checklist items, and specifies the release impact with changeset generation.
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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant