You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR introduces a NarrowableNoInfer<T> type in useQuery.ts, a distributive conditional type wrapping NoInfer<T>, applied to TData across the three useQuery overload return types. A new type-level test verifies discriminated-union narrowing is preserved.
Changes
NarrowableNoInfer Fix
Layer / File(s)
Summary
NarrowableNoInfer type and overload updates packages/react-query/src/useQuery.ts
Adds NarrowableNoInfer<T> conditional type wrapping NoInfer<T> and applies it to TData in DefinedInitialDataOptions, UndefinedInitialDataOptions, and UseQueryOptions overload return types.
Discriminated-union narrowing type test packages/react-query/src/__tests__/useQuery.test-d.tsx
Adds a new type test confirming query.data?.type === 'first' ? undefined : query.data narrows correctly to the 'second' variant or undefined.
i would rather just revert and remove the NoInfer from the return type. we don’t do this anywhere else and the bug that it fixed is questionable at best.
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
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
useQueryreturn-typeNoInferfence in a distributive helperUseQueryResultannotationsquery.data#11018Closes #11018
✅ Checklist
pnpm run test:pr.pnpm --filter @tanstack/react-query test:types:tscurrent🚀 Release Impact