setQueryData: NoInfer loses discriminated-union members when spreading a narrowed updater value
I maintainer di solito rispondono entro 1 giorno
@iosayin ci sta già lavorando.
Dal 4/10/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- typescript
- Ambito
- api, developer-experience
Direzione di ricerca
Start with the minimal TypeScript reproduction and the setQueryData updater type definitions; inspect how the queryOptions key determines the updater parameter and how narrowing a discriminated union is represented. Run the provided tsc command, and consider the issue complete when the unannotated updater compiles while preserving the expected variant-specific fields without regressing related type behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
With @tanstack/[email protected], setQueryData infers the correct data type from a queryOptions key, but narrowing and spreading that union inside the updater produces a false assignability error. Explicitly annotating the updater parameter as Data | undefined makes the same code compile.
Minimal reproduction
import { QueryClient, queryOptions } from '@tanstack/react-query';
type Data =
| { kind: 'a'; value: number; requiredA: number }
| { kind: 'b'; value: number; requiredB: number };
const query = queryOptions({
queryKey: ['probe'],
queryFn: async (): Promise<Data> => ({ kind: 'a', value: 1, requiredA: 1 }),
});
const client = new QueryClient();
client.setQueryData(query.queryKey, (prev) => {
if (!prev || prev.kind !== 'a') return prev;
return { ...prev, value: prev.value + 1 };
});
Run with TypeScript 5.8.3:
tsc --noEmit --strict --skipLibCheck --target es2023 --moduleResolution bundler --module esnext repro.ts
Actual behavior
TS2345: the callback return is inferred as NoInfer<Data> | { value: number; kind: 'a' | 'b' } | undefined. The spread loses the variant-specific required fields, so the returned object is rejected as Data.
Expected behavior
After the guard, spreading prev should preserve kind: 'a' and requiredA. The updater should compile without repeating the data type already encoded in the query key.
Workaround
Changing only (prev) to (prev: Data | undefined) compiles.
Versions and related context
@tanstack/react-query: 5.104.0- TypeScript: 5.8.3
- Reproduces during typechecking; no browser or network calls needed.
Related: #11018 and #11245 address the useQuery return type. This report concerns the remaining NoInfer interaction in QueryClient.setQueryData updater parameters. The inferred key type itself is correct; the failure occurs during union narrowing/spread.
- Lingua principale
- TypeScript
- Stelle
- 50.4k
- Fork
- 4.2k
- Merge medio
- 11h 33m
- PR unite (30g)
- 421
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/query
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/query#11358 · 2 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)Forse già presa @MaNaN1803 l’ha presa 73 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/query#11106 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
I maintainer di solito rispondono entro 1 giorno
-
setQueryData updater loses discriminated-union fields when spreading inferred NoInfer dataForse già presa @boriskozak l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
TanStack/query#11794 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[vue-query]: UseMutationReturnType default names unexported MutationResult (TS2883) 🤖🤖🤖Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/query
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr impact:session-state issue-rating: 🌊 off-meta tidepool P2
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
openclaw/openclaw#165245 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
agent-canvas bug priority:low ready-for-dev
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
spicetify/marketplace#1262 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno