T
tRPC

❓-help

TypeScript type for request object for route handlers

Mmeow4/10/2023
So far I've been writing my routes like:
export const router = t.router({
helloWorld: t.procedure.query(async (req) => "Hello World"),
})
export const router = t.router({
helloWorld: t.procedure.query(async (req) => "Hello World"),
})
What would be the type for req if I wanted to extract my handlers like so:
const handler = async (req:?) => "Hello World"

export const router = t.router({
helloWorld: t.procedure.query(hander)
})
const handler = async (req:?) => "Hello World"

export const router = t.router({
helloWorld: t.procedure.query(hander)
})
Nnlucas4/10/2023
You'll have a really hard time extracting your handlers in some cases, but for this simple example you can just use some typescript magic
type QueryInputs = Parameters<typeof t.procedure.query>[0]
type QueryInputs = Parameters<typeof t.procedure.query>[0]
Mmeow4/10/2023
ah thx

Looking for more? Join the community!