Skip to content
Source
Sign inSign up
TanStack/query

vue-query: UseQueryOptions no longer assignable to queryClient.query() since 5.103.0 #12452

Closedspaansba(GitHub profile, opens in a new tab) opened this issue 4 comments

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

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgRQK4FMoE8DCAbYdAOxgBo4Ysx04BVAZ3TUywHkwZgIj64BfOADMoEEHADkAARgBDHrIDGAawD0ANwwBaAI4Zs4gFAGAJugV4ZUGgu714EDlx4AuOo2bZ2nWwB4iqEAAjTAA+Ixt5OF0WfEISOABeOCJ0AHcUPVwCYhgACgBKIxUVOBxRMGA8dF5uOABWADoARgAGACYGlvIAFQBlNoB2ADYATjh6YCIFGkbWgGZOgzUIYGMozNichujsXIdvHkKgA

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)
  1. Install @tanstack/vue-query@5.103.0 or newer
  2. Type-check the snippet
  3. 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().

  1. duongynhi000005-oss(GitHub profile, opens in a new tab)commented

    I investigated #12452 and traced the type mismatch between packages/vue-query/src/queryOptions.ts and packages/vue-query/src/queryClient.ts:

    Root Cause

    In packages/vue-query/src/queryOptions.ts:68-86, UseQueryOptions widens queryFn to include SkipTokenForUseQuery (type SkipTokenForUseQuery = symbol) so ref(skipToken) can be inferred without as const. However, in packages/vue-query/src/queryClient.ts:290-348, QueryClient.query() (as well as fetchQuery() and prefetchQuery()) only accepts MaybeRefDeep<QueryExecuteOptions<...>>, where queryFn only permits @tanstack/query-core's typeof skipToken (unique symbol). Because symbol is not assignable to unique symbol, passing an explicitly typed UseQueryOptions into queryClient.query(options) fails with TS2769.

    Proposed Fix

    Update the QueryClient.query, fetchQuery, and prefetchQuery signatures in packages/vue-query/src/queryClient.ts to accept UseQueryOptions (or SkipTokenForUseQuery on queryFn), and add a regression type test in packages/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!

  2. peterbud(GitHub profile, opens in a new tab)commented

    Isn't this similar to #11639, and fixed in #11644 ?

  3. spaansba(GitHub profile, opens in a new tab)commented

    @peterbud you are right, this is a duplicate of #11639. Thanks for letting me know

Sign in to join this conversation.