Uh oh!
There was an error while loading. Please reload this page.
fix({react,preact}-query): add NoInfer to infinite and suspense hook return types - #11164
fix({react,preact}-query): add NoInfer to infinite and suspense hook return types#11164S-jooyoung wants to merge 1 commit into
Conversation
…return types Extends the NoInfer fence that useQuery's return types already have to useInfiniteQuery, useSuspenseQuery, and useSuspenseInfiniteQuery, so an explicitly annotated result type can no longer reverse-infer TData. Uses a distributive wrapper (T extends unknown ? NoInfer<T> : never) instead of plain NoInfer so discriminated-union narrowing on data keeps working (see TanStack#11018). FixesTanStack#8639 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughReact Query and Preact Query hooks now use distributive ChangesQuery hook type inference
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx`:
- Line 178: Remove the duplicate `{ type: 'second'; second: string }` member
from each affected type assertion, retaining exactly one member in
packages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsx:178,
packages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsx:129, and
packages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsx:118. Preserve
the surrounding NarrowableNoInfer assertions.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: cc8a149c-fd6a-4ab5-a1f5-5016d40cf785
📒 Files selected for processing (13)
.changeset/noinfer-infinite-suspense-hooks.mdpackages/preact-query/src/__tests__/useInfiniteQuery.test-d.tsxpackages/preact-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsxpackages/preact-query/src/__tests__/useSuspenseQuery.test-d.tsxpackages/preact-query/src/useInfiniteQuery.tspackages/preact-query/src/useSuspenseInfiniteQuery.tspackages/preact-query/src/useSuspenseQuery.tspackages/react-query/src/__tests__/useInfiniteQuery.test-d.tsxpackages/react-query/src/__tests__/useSuspenseInfiniteQuery.test-d.tsxpackages/react-query/src/__tests__/useSuspenseQuery.test-d.tsxpackages/react-query/src/useInfiniteQuery.tspackages/react-query/src/useSuspenseInfiniteQuery.tspackages/react-query/src/useSuspenseQuery.ts
Uh oh!
There was an error while loading. Please reload this page.
🎯 Changes
Follow-up to #8639:
useQuery's return types already fenceTDatawithNoInfer, butuseInfiniteQuery,useSuspenseQuery, anduseSuspenseInfiniteQuerystill let an explicitly annotated result type reverse-inferTData— an annotation that contradicts the actualqueryFn/selecttype compiles fine and then fails at runtime (the scenario reported in #8639).TDatain the return types ofuseInfiniteQuery(all three overloads),useSuspenseQuery, anduseSuspenseInfiniteQuery, in bothreact-queryandpreact-query(mirroring the cross-package approach of fix({react,preact}-query): default 'TData' of infinite query options to 'InfiniteData' #11147).type NarrowableNoInfer<T> = T extends unknown ? NoInfer<T> : never) instead of plainNoInfer: plainNoInferbreaks negative-branch discriminated-union narrowing ondata— the regression useQuery return type NoInfer preserves reverse-inference guard but breaks discriminated-union narrowing #11018 reports foruseQuery, and the same shape fix(react-query): preserve narrowing with NoInfer #11022 proposes there. I kept the helper file-local to avoid touchinguseQuery.tsand conflicting with that PR; happy to consolidate once either lands.useQuerytest) plus a discriminated-union narrowing case.Runtime behavior is unchanged — types only.
✅ Checklist
pnpm run test:pr.🚀 Release Impact
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests