T
tRPC

❓-help

How can i use inferprocedureoutput?

Ffunki12/26/2023
I'd like to write this code type-safely:
const handleQuery = (query: /* ? */) => {}

const MyComponent = () => {
const query = trpc.foo.useQuery()
handleQuery(query)
// ...
}
const handleQuery = (query: /* ? */) => {}

const MyComponent = () => {
const query = trpc.foo.useQuery()
handleQuery(query)
// ...
}
I'm pretty sure i need to use inferProcedureOutput but i couldn't figure out what to pass. I can never access query.isLoading for example.
Ffunki12/26/2023
Seems like i actually need something like
type RouterOutputs = inferRouterOutputs<AppRouter>
UseTRPCQueryResult<RouterOutputs["foo"], TRPCClientErrorLike<AppRouter>>
type RouterOutputs = inferRouterOutputs<AppRouter>
UseTRPCQueryResult<RouterOutputs["foo"], TRPCClientErrorLike<AppRouter>>
but i don't understand why i need to pass TRPCClientErrorLike
AKAlex / KATT 🐱12/27/2023
Inferring Types | tRPC
It is often useful to access the types of your API within your clients. For this purpose, you are able to infer the types contained in your AppRouter.

Looking for more? Join the community!