Skip to content

fix(preact-query): infer infinite pageParam in useInfiniteQuery return type#10841

Open
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/preact-infinite-query-pageparam-types-clean
Open

fix(preact-query): infer infinite pageParam in useInfiniteQuery return type#10841
raashish1601 wants to merge 1 commit into
TanStack:mainfrom
raashish1601:fix/preact-infinite-query-pageparam-types-clean

Conversation

@raashish1601
Copy link
Copy Markdown
Contributor

@raashish1601 raashish1601 commented May 30, 2026

Summary

  • Improve preact-query useInfiniteQuery return typing so the default InfiniteData pageParam infers TPageParam instead of staying unknown.
  • Update type tests in packages/preact-query/src/tests/useInfiniteQuery.test-d.tsx to assert concrete InfiniteData<..., number> for default data with initialPageParam: number.

Validation

  • corepack pnpm exec prettier --check packages/preact-query/src/useInfiniteQuery.ts packages/preact-query/src/tests/useInfiniteQuery.test-d.tsx
  • corepack pnpm --filter @tanstack/preact-query test:lib (passes tests, but reports pre-existing typecheck errors on
    oot.eslint.config.js and
    oot.tsup.config.js).
  • corepack pnpm --filter @tanstack/preact-query test:types:tscurrent (fails for same workspace config parse issue).

Summary by CodeRabbit

  • Bug Fixes

    • Improved TypeScript type safety and inference for infinite query operations to correctly resolve page parameter types in return values.
  • Tests

    • Updated type assertions to reflect corrected type inference behavior.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 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: 8994b043-dd4d-4bb8-a10b-216a81026ed2

📥 Commits

Reviewing files that changed from the base of the PR and between 7fa2781 and 5c7f5d3.

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

📝 Walkthrough

Walkthrough

This PR updates TypeScript type inference in useInfiniteQuery by introducing conditional helper types that correctly resolve the page-parameter generic within InfiniteData. Three function overloads now apply this resolution, and type assertions in tests validate the corrected inference behavior.

Changes

Page-Param Type Resolution in useInfiniteQuery

Layer / File(s) Summary
Conditional type helpers for page-param resolution
packages/preact-query/src/useInfiniteQuery.ts
Internal helper types IsUnknown and ResolvePageParamData detect when TData is shaped like InfiniteData and conditionally replace unknown or never page-param types with the provided TPageParam.
Apply page-param helpers to all overloads
packages/preact-query/src/useInfiniteQuery.ts
All three useInfiniteQuery overloads now use ResolvePageParamData in their return type generics, ensuring page-parameter type is correctly inferred instead of remaining unknown or never.
Type assertion updates in tests
packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx
Type assertions for infiniteQuery.data are updated to expect number (instead of unknown) for the page-parameter generic in both the select and getNextPageParam / getPreviousPageParam test cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Page params were lost in the TypeScript haze,
Now type helpers guide through the generic maze,
Three overloads shine with precision true,
Infinite queries now know just what to do! 📊✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description provides a clear summary and validation details, but does not follow the provided template structure with the required sections (🎯 Changes, ✅ Checklist, 🚀 Release Impact). Restructure the description to follow the template: use the required section headings (🎯 Changes, ✅ Checklist, 🚀 Release Impact) and include the mandatory checklist items and release impact declaration.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: improving TypeScript type inference for the pageParam in useInfiniteQuery's return type.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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