Hussam
Hussam2y ago

How to infer types of a query

Coinsider the example const hello = trpc.hello.useQuery(); I would like to export the type we get on hover(on hello). I could only find how to infer the data type from the docs const { data } = trpc.hello.useQuery() https://trpc.io/docs/infer-types using inferRouterOutputs The reason I am passing everything and not just data as props down to components, is because I want to access the loading, error states etc.
Inferring Types | tRPC
It is often useful to wrap functionality of your @trpc/client or @trpc/react-query api within other functions. For this purpose, it's necessary to be able to infer input types and output types generated by your @trpc/server router.
2 Replies
Nick
Nick2y ago
The query type is a React Query thing, it’s a little customised but generally the types they export will probably work for you You could also ‘ReturnType<typeof trpc.hello.useQuery>’
Hussam
HussamOP2y ago
this does not work. I am trying to look into the other option. thanks a lot Nick Ended up using QueryObserverResult import { QueryObserverResult } from '@tanstack/react-query';