Describe the bug
Hello,
I'm using query to fetch some data coming from the server using Vue, the code looks like this:
const{ error, data, status }=useQuery({queryKey: ['units',page],queryFn: ()=>axios.get<PaginatedResponse<Unit>>('/api/units?page='+page.value),select: (response)=>response.data,placeholderData: keepPreviousData,})per docs, if status == success or isSuccess is true, we should have data defined with type from the calling queryFn. However it appears by @tanstack/query-core type definition that this is not the case:
interfaceSuccessAction<TData>{data: TData|undefinedtype: 'success'dataUpdatedAt?: numbermanual?: boolean}Is this wanted due to uncertainty of the data being returned? If that so, shouldn't this be responsibility of the type definition of the called queryFn?
Your minimal, reproducible example
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ5wC+cAZlBCHAOQACMAhgHaoMDGA1gPQBuOAtAEcc+KgFgAUBImsIzeEgAm9BgBo4wVAGVkrVulSoicALwoM2XHgAUCCXHtwhlgGKMAXHCsBKEwD44AArkIBroAHRQ+hAANtzoVgCsXip2Dk74ANLoeB4A2lQw+jBUALoShF5S4sAknhrauvqoPrbiDnBKDBKcnPYAegD85RJAA
Steps to reproduce
Simply check in typescript playground, data is of type Ref<number, number> | Ref<undefined, undefined> even when resolved and inside a if check for success
Expected behavior
Per doc, this shouldn't be allowed
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Issue is platform agnostic
Tanstack Query adapter
vue-query
TanStack Query version
v5.76.0
TypeScript version
5.8.3
Additional context
No response
Describe the bug
Hello,
I'm using query to fetch some data coming from the server using Vue, the code looks like this:
per docs, if
status==successorisSuccessis true, we should havedatadefined with type from the callingqueryFn. However it appears by@tanstack/query-coretype definition that this is not the case:Is this wanted due to uncertainty of the data being returned? If that so, shouldn't this be responsibility of the type definition of the called
queryFn?Your minimal, reproducible example
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ5wC+cAZlBCHAOQACMAhgHaoMDGA1gPQBuOAtAEcc+KgFgAUBImsIzeEgAm9BgBo4wVAGVkrVulSoicALwoM2XHgAUCCXHtwhlgGKMAXHCsBKEwD44AArkIBroAHRQ+hAANtzoVgCsXip2Dk74ANLoeB4A2lQw+jBUALoShF5S4sAknhrauvqoPrbiDnBKDBKcnPYAegD85RJAA
Steps to reproduce
Simply check in typescript playground,
datais of typeRef<number, number> | Ref<undefined, undefined>even when resolved and inside aifcheck forsuccessExpected behavior
Per doc, this shouldn't be allowed
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Issue is platform agnostic
Tanstack Query adapter
vue-query
TanStack Query version
v5.76.0
TypeScript version
5.8.3
Additional context
No response