T
TanStack4y ago
stormy-gold

What is the return type of useQuery?

I have a composable that runs useQuery and specifies a return type of: UseQueryReturnType<TypedMaterial[], unknown> I get the error "TS2322: Type 'UseQueryReturnType<TypedMaterial[], unknown>' is not assignable to type 'UseQueryReturnType<TypedMaterial[], unknown, QueryObserverResult<TypedMaterial[], unknown>>" When I change the return type to UseQueryReturnType<TypedMaterial[], unknown, QueryObserverResult<TypedMaterial[], unknown>> I get the error "TS2322: Type 'UseQueryReturnType<TypedMaterial[], unknown>' is not assignable to type 'UseQueryReturnType<TypedMaterial[], unknown, QueryObserverResult<TypedMaterial[], unknown>>'."
2 Replies
correct-apricot
correct-apricot4y ago
You do not have to type it manually. Typescript should be able to automatically infer the return type. The only thing you need to type is probably your queryFn
stormy-gold
stormy-goldOP4y ago
that is true it doesnt have to be typed but I have a rule to type every function return type

Did you find this page helpful?