fix({react,preact}-query): add NoInfer to infinite and suspense hook return types - #11164
Open
S-jooyoung wants to merge 1 commit into
Open
fix({react,preact}-query): add NoInfer to infinite and suspense hook return types#11164S-jooyoung wants to merge 1 commit into
S-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). Fixes TanStack#8639 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
📝 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 |
Contributor
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 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