Describe the bug
queryOption type inference broken when using computed queryOption with select option
Your minimal, reproducible example
Sorry I couldn't find an existed vue example with tanstack query v5 set up to edit upon. But the steps should be really simple to reproduce
Steps to reproduce
1. Create a dynamic queryOption
const postsByUserIdQueryOption = (userId: string) => queryOption(...)
2. Use the computed queryOption in the component
const { data: posts } = useQuery(computed(() => postsByUserIdQueryOption(userId.value)))
3. Spread the options and add an enabled option - it works ✅
const { data: posts } = useQuery(computed(() => ({
...postsByUserIdQueryOption(userId.value),
enabled: !!userId.value
})))
4. Add a select option - type error occurs ❌
const { data: postCount } = useQuery(computed(() => ({
...postsByUserIdQueryOption(userId.value),
enabled: !!userId.value,
select: (data) => data.length // Monstrous typescript error
})))
but this ↓ non-dynamic queryOption without computed will work and postCount is correctly inferred to be a number ✅
const { data: postCount } = useQuery({
...postsByUserIdQueryOption(userId.value),
enabled: !!userId.value,
select: (data) => data.length
})
5. Manually type data - fixes the type error ✅
const { data: postCount } = useQuery(computed(() => ({
...postsByUserIdQueryOption(userId.value),
enabled: !!userId.value,
select: (data: Post[]) => data.length
})))
Here ↓, it will also not infer correctly
const queryOption = computed(() => ({
...getPostsByUserIdQueryOption(userId.value)
enabled: !!userId.value,
select: (data) => data.length // typescript error here, data can be any, instead of the return type of queryFn defined inside queryOption
}))
Expected behavior
when having something like this
const { data: postCount } = useQuery(computed(() => ({
...postsByUserIdQueryOption(userId.value),
enabled: !!userId.value,
select: (data) => data.length
})))
the data parameter in select callback should be automatically inferred to the same type as the return type of queryFn provided in queryOption
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Tanstack Query adapter
None
TanStack Query version
v5.83.0
TypeScript version
5.4.5
Additional context
No response
Describe the bug
queryOption type inference broken when using computed queryOption with
selectoptionYour minimal, reproducible example
Sorry I couldn't find an existed vue example with tanstack query v5 set up to edit upon. But the steps should be really simple to reproduce
Steps to reproduce
1. Create a dynamic queryOption
2. Use the computed queryOption in the component
3. Spread the options and add an
enabledoption - it works ✅4. Add a
selectoption - type error occurs ❌but this ↓ non-dynamic queryOption without
computedwill work andpostCountis correctly inferred to be a number ✅5. Manually type
data- fixes the type error ✅Here ↓, it will also not infer correctly
Expected behavior
when having something like this
the
dataparameter inselectcallback should be automatically inferred to the same type as the return type ofqueryFnprovided in queryOptionHow often does this bug happen?
None
Screenshots or Videos
No response
Platform
Tanstack Query adapter
None
TanStack Query version
v5.83.0
TypeScript version
5.4.5
Additional context
No response