Branded queryKey in queryOptions causes TS error (TS2769) in useQuery
I maintainer di solito rispondono entro 1 giorno
@byungsker ci sta già lavorando.
Dal 25/4/2026.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- frontend
Direzione di ricerca
Inizia con il CodeSandbox collegato e la sua riproduzione in src/Post.vue, quindi segui gli overload TypeScript utilizzati da queryOptions e useQuery nell’adapter Vue. Conferma la correzione facendo compilare l’helper queryKey branded senza TS2769, preservando i casi funzionanti fetchQuery e useQuery inline.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
I’m encountering a TypeScript overload mismatch (TS2769) when calling useQuery() with the result of a queryOptions(...) function whose returned object contains a queryKey with a branded type. The error occurs specifically when useQuery() receives the output of queryOptions(...) containing a branded value in queryKey.
Passing the same options to queryClient.fetchQuery(queryOptions(queryKey: brandedKey, queryFn)) — works fine.
Passing the branded key inline to useQuery (i.e. useQuery({ queryKey: brandedKey, queryFn})) — works fine.
Your minimal, reproducible example
https://codesandbox.io/p/devbox/tanstack-query-ts-error-2769-forked-spc8jh?file=%2Fsrc%2FPost.vue
Steps to reproduce
1. Define a branded type in your code:
type PostId = string & { readonly __brand: "PostId" };
2. Create a helper function that returns queryOptions where the queryKey includes a value using this branded type:
const getPostQueryOptions = (
params: MaybeRefOrGetter<{ postId: PostId }>
) => {
return queryOptions({
queryKey: ["post", params],
queryFn: () => fetcher(toValue(params).postId),
});
};
3. Call useQuery() using the result of this helper:
useQuery(getPostQueryOptions({ postId }));
4. Observe the TypeScript error:
No overload matches this call.
Overload 1 of 3, '(options: DefinedInitialQueryOptions<Post, Error, Post, MaybeRefDeep<string | (() => { postId: PostId; }) | { postId: PostId; }>[]>, queryClient?: QueryClient | undefined): UseQueryDefinedReturnType<...>', gave the following error.... ts(2769)
Expected behavior
useQuery() should correctly accept a QueryOptions object whose queryKey contains a branded (nominal) type.
In other words:
Passing the result of queryOptions(...) or any helper function that returns a QueryOptions object should not trigger a TypeScript overload error, even if the queryKey includes branded values.
How often does this bug happen?
Every time
Screenshots or Videos
Platform
- OS [Windows]
- Browser [Chrome]
Tanstack Query adapter
vue-query
TanStack Query version
v5.85.3
TypeScript version
v5.9.2
Additional context
No response
- Lingua principale
- TypeScript
- Stelle
- 50.4k
- Fork
- 4.2k
- Merge medio
- 7h 29m
- PR unite (30g)
- 393
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 75 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
-
restoreQueries and persisterGc throw on malformed persisted entriesForse già presa @VGontier-cmd l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
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: NoInfer loses discriminated-union members when spreading a narrowed updater valueForse già presa @iosayin l’ha presa 2 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/query
Issue simili
-
triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
github/docs#46222 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
agent-ready area: config area: skills type: chore upstream: brain-kit
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
-
enhancement priority:low ready-for-dev
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
bug escritorio mapa
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
marcosferr/reporte-ciudadano#4 · 1 commento ·
-
area: material/sort gemini-triaged needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
angular/components#33933 ·
I maintainer di solito rispondono entro 1 giorno