Svelte: passing a store to createQuery breaks types when using `select`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- typescript
- 领域
- frontend
调研方向
在链接的 TypeScript playground 中重现该问题,将 createQuery 分别与直接的 options 对象和派生 store 进行比较。从 Svelte 的 createQuery 类型定义入口开始,跟踪 select 如何接收其数据类型。当通过派生 store 传递 options 时 select 能够被正确推断,且不会破坏现有的直接对象行为时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
using the latest version of tanstack query svelte, passing derived store and using select to select subset of the data makes the data in select type any and breaks the query types.
Playground link: https://tsplay.dev/mpkn6N
Example. This works:
// query type works as expected
const queryThatWorks = createQuery(
derived(intervalMs, ($intervalMs) => ({
queryKey: ["refetch"],
queryFn: async () => ({ a: { b: { c: "" } } }),
refetchInterval: $intervalMs,
})),
);
const result1 = get(queryThatWorks)?.data;
// ^? const result: {a: Eb: { c: string; 3; };..
this doesn't:
// `select` data is type any
const queryWithBrokenTypes = createQuery(
derived(intervalMs, ($intervalMs) => ({
queryKey: ["refetch"],
queryFn: async () => ({ a: { b: { c: "" } } }),
refetchInterval: $intervalMs,
// data type is any, never inferred
select: (data) => data,
// ^? (parameter) data: any
})),
);
const result2 = get(queryWithBrokenTypes)?.data;
// ^? const result2: any
this shows that select works without derived:
// `select` works without `derived`
const queryWithSelectWorks = createQuery({
queryKey: ["refetch"],
queryFn: async () => ({ a: { b: { c: "" } } }),
// data type is any, never inferred
select: (data) => data,
// ^? (parameter) data: {a: {b: { c: string; ) ;..
});
const result3 = get(queryWithSelectWorks)?.data;
// ^? const result3: { a: {b: (c: string; ); );
Your minimal, reproducible example
Steps to reproduce
- create a query in svelte,
- pass a
derivedstore, - use
selectin the query, - notice how
datatype isany.
see twoslash shiki comments
Expected behavior
it should not break types when passing a store and using select to createQuery
How often does this bug happen?
Every time
Screenshots or Videos
Platform
all
Tanstack Query adapter
svelte-query
TanStack Query version
^5.49.1
TypeScript version
6.5.2
Additional context
No response
- 主要语言
- TypeScript
- 星标
- 50.4k
- 派生
- 4.2k
- 平均合并
- 13 小时 33 分钟
- 30 天内合并 PR
- 383
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/query 的其他 Issue
-
[angular-query] injectDevtoolsPanel doesn't support the 'theme' option可能已有人在做 @benjavicente 于 1 天前认领。 未关闭package: angular-query-devtools
难度 2/5 1-3 小时 新手友好度 76/100
TanStack/query#11680 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
TanStack/query#11358 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
TanStack/query#11106 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 68/100
TanStack/query#11794 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 86/100
tomjn/coilbox-hub#454 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
api: spanner
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/google-cloud-node#9513 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 1 天内回复
-
SegmentedControl calls Math.random() during render, breaking Next.js cacheComponents prerendering未关闭
难度 2/5 1-3 小时 新手友好度 76/100
mantinedev/mantine#9244 ·
维护者通常 8 天内回复