setQueryData: NoInfer loses discriminated-union members when spreading a narrowed updater value
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- api, developer-experience
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 50.4k
- Forks
- 4.2k
- Merge medio
- 13 h 33 min
- PR fusionados (30 d)
- 383
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/query
-
[angular-query] injectDevtoolsPanel doesn't support the 'theme' optionPosiblemente ocupada @benjavicente la tomó hace 1 día. Abiertopackage: angular-query-devtools
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
TanStack/query#11680 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Quizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/query#11358 · 2 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
solid-query: switching the queryClient accessor strands the new client's cache (subscription stays on the old observer)Posiblemente ocupada @MaNaN1803 la tomó hace 73 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
TanStack/query#11106 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
TanStack/query#11794 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[vue-query]: UseMutationReturnType default names unexported MutationResult (TS2883) 🤖🤖🤖Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/query
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
prime-radiant-inc/evener#3726 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
FuRongJun-1999/dsh-memory#56 ·
Los mantenedores suelen responder en 1 día
-
bug via-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
pingdotgg/t3code#15682 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
openwatersio/slackwater.xyz#152 ·
Los mantenedores suelen responder en 1 día
-
[BUG] 请修改标题为您遇到的问题Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
OpenListTeam/OpenList-Worker#103 ·
Los mantenedores suelen responder en 1 día