fix(react-query): preserve narrowing with NoInfer #11022
ClosedGujiassh(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/11022/headopened View on GitHubTkDodo closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
This PR introduces a
NarrowableNoInfer<T>type inuseQuery.ts, a distributive conditional type wrappingNoInfer<T>, applied toTDataacross the threeuseQueryoverload return types. A new type-level test verifies discriminated-union narrowing is preserved.Changes#
NarrowableNoInfer Fix
packages/react-query/src/useQuery.tsNarrowableNoInfer<T>conditional type wrappingNoInfer<T>and applies it toTDatainDefinedInitialDataOptions,UndefinedInitialDataOptions, andUseQueryOptionsoverload return types.packages/react-query/src/__tests__/useQuery.test-d.tsxquery.data?.type === 'first' ? undefined : query.datanarrows correctly to the'second'variant orundefined.Estimated code review effort: 2 (Simple) | ~10 minutes
Possibly related PRs
useQuery'sNoInfertyping that this PR fixes a regression from.NoInfer-driven type-inference fix in a related query generics area.Suggested labels:
package: react-querySuggested reviewers:
TkDodo🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#11018by wrapping NoInfer distributively, preserving the reverse-inference guard, and adding narrowing coverage.✨ 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.
❤️ Share