vue-query: UseQueryOptions no longer assignable to queryClient.query() since 5.103.0 #12452
Describe the bug#
Since 5.103.0, a value typed as UseQueryOptions is no longer accepted by queryClient.query(). It fails with TS2769. The deprecated prefetchQuery / fetchQuery fail the same way.
#11439 added type SkipTokenForUseQuery = symbol to queryFn in UseQueryOptions. The MaybeRefDeep<...> overloads on QueryClient still expect typeof skipToken, so a plain symbol no longer fits. Options inferred through queryOptions() are fine. Only values annotated or cast as UseQueryOptions break, which is what code generators emit.
Your minimal, reproducible example#
Steps to reproduce#
import { QueryClient, type UseQueryOptions } from '@tanstack/vue-query'
declare const options: UseQueryOptions<number>
const queryClient = new QueryClient()
// Compiles on 5.102.0, TS2769 since 5.103.0
void queryClient.query(options)
- Install
@tanstack/vue-query@5.103.0or newer - Type-check the snippet
- See TS2769
Expected behavior#
A UseQueryOptions value is accepted by queryClient.query(), as in 5.102.0.
How often does this bug happen?#
Every time
Platform#
Type-check only (tsc / vue-tsc), macOS
Tanstack Query adapter#
vue-query
TanStack Query version#
v5.103.0 (still present in v5.105.0)
TypeScript version#
v6.0.3
Additional context#
Found through Orval's generated vue-query prefetch*Query helpers, which cast their options to UseQueryOptions before calling queryClient.query().
spaansba(GitHub profile, opens in a new tab) changed the title
I investigated #12452 and traced the type mismatch between
packages/vue-query/src/queryOptions.tsandpackages/vue-query/src/queryClient.ts:Root Cause#
In
packages/vue-query/src/queryOptions.ts:68-86,UseQueryOptionswidensqueryFnto includeSkipTokenForUseQuery(type SkipTokenForUseQuery = symbol) soref(skipToken)can be inferred withoutas const. However, inpackages/vue-query/src/queryClient.ts:290-348,QueryClient.query()(as well asfetchQuery()andprefetchQuery()) only acceptsMaybeRefDeep<QueryExecuteOptions<...>>, wherequeryFnonly permits@tanstack/query-core'stypeof skipToken(unique symbol). Becausesymbolis not assignable tounique symbol, passing an explicitly typedUseQueryOptionsintoqueryClient.query(options)fails withTS2769.Proposed Fix#
Update the
QueryClient.query,fetchQuery, andprefetchQuerysignatures inpackages/vue-query/src/queryClient.tsto acceptUseQueryOptions(orSkipTokenForUseQueryonqueryFn), and add a regression type test inpackages/vue-query/src/__tests__/queryClient.types.test.ts.I have a branch ready (
duongynhi000005-oss/query:fix-issue-12452-vue-query-client-accept-usequeryoptions) and would be glad to open a PR!@peterbud you are right, this is a duplicate of #11639. Thanks for letting me know
spaansba(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Can open a PR if needed