Svelte: passing a store to createQuery breaks types when using `select`
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 50.3k
- Forks
- 4.2k
- Avg merge
- 18h 25m
- Merged PRs (30d)
- 200
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the linked TypeScript playground, comparing createQuery with a direct options object and with a derived store. Start at the Svelte createQuery typing entry point and trace how select receives its data type. Done means select is inferred correctly when options are passed through a derived store, without breaking the existing direct-object behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100