I want to create a wrapper for TRPC.init but I can't seem to get the context type correct.
I want to get wrap trpc.init
3 Replies
create-context.ts
and I want to do:
but when I do:
t.context is of type {} when I do that 😦
You do
Awaited<typeof createContext>
but createContext isn't async so that doesn't do anything.
I'd recommend just starting over with initTRPC.context<{test: string}>.create(...);
and keep building up slowly to the more complex type you have until you find the error you madeit works, the problem is with the generic type
makeTRPC<T> always resolves to {}
even without the Awaited, it results in the same output
thanks for the answer by th eway
was able to resolve it using type inference:
type LocalContext<T> = inferAsyncReturnType<typeof createInternalContext<T>>
export type Context<T> = T extends infer R ? LocalContext<R> : never