Andrew4w ago

Procedure passed as argument to function loses type safety.

Hi there, I have a mystifying TS issue, where I lose type safety of my proc when I pass it as an argument to another function. I'm new to tRPC, and been doing a spike to see if we can adopt it at our company. Full code example is in this TS playground: The issue is that with the definition of createTRPCEndpoint, the returned procedure loses the type definition of input. I've simplified it to the point that createTRPCEndpoint has no utility, but we use it to dynamically create middleware that are configured by the options we pass in. It would be important to be able to enrich the procedure ctx type with the middleware. If we didn't, we could override and cast the return type of createTRPCEndpoint as T, and then the type safety of input is preserved, but then we can't enrich ctx. Has anyone had success with passing procedures to other functions without losing their type safety? I'm wondering if there's some typing helpers that I'm missing, or other creative ways of solving this problem. Thanks for your time! 🙏 Env: Node 18, yarn 4.0.2, npm 10.5.0.
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
0 Replies
No replies yetBe the first to reply to this messageJoin