Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[vue-query] useQuery rejects spreading a queryOptions() result + override since v5.98.0

未关闭
#10,904 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
typescript
领域
frontend

调研方向

从 queryOptions 和 useQuery 入口开始进行最小复现,针对 5.97.0 和 5.98.0+ 版本运行 tsc --noEmit 或 vue-tsc。跟踪 spread 形式所涉及的 queryKey branding 和选项推断;当文档中的 spread-and-override 示例能够在没有 TS2769 的情况下通过类型检查,同时直接使用 useQuery(opts) 仍然有效时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

Since @tanstack/vue-query v5.98.0, the documented pattern of spreading a queryOptions(...) result into useQuery and overriding a non-data-shaping option (e.g. enabled) no longer type-checks. Passing the same options object directly works; only the spread + override form fails.

This is a downstream continuation of #10525. That fix made queryOptions({ queryKey: computed(...) }) type-check again, but the branded queryKey (DataTag<...>) is still inconsistent with the other option properties once the result is spread into a fresh object literal, so useQuery inference fails with TS2769: No overload matches this call.

The most revealing part of the error cascade:

Types of property 'staleTime' are incompatible.
  ...
  Type 'readonly ["activity", "detail", string | null | undefined]' is not assignable to type
    '{ ...; [dataTagErrorSymbol]: Error; }'.
Your minimal, reproducible example
import { queryOptions, useQuery } from "@tanstack/vue-query"
import { computed, type MaybeRefOrGetter, toValue } from "vue"

const fooQueryOptions = (id: MaybeRefOrGetter<string | null>) =>
  queryOptions({
    queryKey: computed(() => ["foo", toValue(id)] as const),
    queryFn: async () => {
      const v = toValue(id)
      return v ? { id: v } : null
    },
  })

// ✅ OK — passed directly
useQuery(fooQueryOptions("1"))

// ❌ TS2769 since 5.98.0 (works on 5.97.0) — spread + override
useQuery({
  ...fooQueryOptions("1"),
  enabled: () => true,
})
Steps to reproduce
  1. Install @tanstack/[email protected] (or any version from 5.98.0 onward).
  2. Define a queryOptions(...) factory with a computed queryKey.
  3. Spread its result into useQuery({ ...opts, enabled: () => true }).
  4. Run tsc --noEmit / vue-tsc.
  5. TypeScript reports TS2769: No overload matches this call, bottoming out at the queryKey missing the dataTagSymbol / dataTagErrorSymbol brand.

Note: useQuery(opts) (passing the same options directly, without spreading or overriding) type-checks fine — only the spread + override form fails.

Expected behavior

Spreading a queryOptions(...) result and overriding enabled (or other non-data-shaping options) should type-check, as shown in the docs and as it did on 5.97.0:
https://tanstack.com/query/latest/docs/framework/vue/guides/query-options

How often does this bug happen?

Every time

Screenshots or videos

No response

Platform
  • TanStack Query version: broken on 5.98.0 – 5.101.0; last working 5.97.0
  • TypeScript version: 5.8+
  • Vue version: 3.5+
Additional context

Same class of regression as #10458 (fixed enabled) and #10525 (fixed queryKey on queryOptions), but it surfaces at the useQuery call site when spreading a queryOptions(...) result and overriding a property. Pinning to 5.97.0 produces zero type errors; any of 5.98.0 – 5.101.0 reproduces it.

主要语言
TypeScript
星标
50.4k
派生
4.2k
平均合并
7 小时 37 分钟
30 天内合并 PR
420

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。