fix(react-query): drop NoInfer from data source state type - #57
Merged
Conversation
DakEnviy
approved these changes
Aug 7, 2026
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.
Problem
If a data source's
fetchreturns a discriminated union, consumers cannot narrowdatadown to a single branch. Any such data source is affected:Narrowing by the discriminant then fails in the most common way of writing it:
This happens regardless of the discriminant's type (string or boolean), and
whether or not the data source declares
transformResponse.Cause
NoInferwas applied to theTStateargument ofPlainQueryDataSource/InfiniteQueryDataSource— the data position of the state.NoInfer<T>isimplemented as a substitution type: transparent for assignability, but not a
union type, so discriminant narrowing does not work through it.
This is not an edge-case syntax issue — it breaks the whole "narrow, then store in
a variable" pattern: narrowing is discarded the moment the type is captured (a
const/letwithout an annotation, an array literal element, a generic callargument).
NoInferis not needed inTState: it is the phantom field[stateHintSymbol]?: TState, never populated by the user, so nothing is everinferred from it.
Solution
NoInferis removed only from theTStateargument. It is kept inTOptions,TFetchContext,next/prev,transformParamsandtags, wherethese are genuine inference positions. The change is type-level only and does not
touch runtime.
After the fix,
datahovers asPayload | undefinedand the narrowedfilledas
{kind: 'filled'; items: string[]} | undefined.Consumers now get narrowed types where narrowing previously failed silently. This
can surface as new compile errors where a narrowed value lands in a mutable slot
and another union branch is written to it later:
Read-only usage is unaffected: a narrower type is assignable everywhere the wider
one was accepted.