Hacker News new | ask | show | jobs
by markoutso 1508 days ago
I am really not getting this. If you run Typescript on both ends, can't you just share the source code that defines the types?
2 comments

You kinda can share function signatures with TypeScript's import type.

And that's what tRPC does but adds some generics in the middle to make things seamless.

Explanation here: https://colinhacks.com/essays/painless-typesafety

You could argue that this is actually adding a lot of (nicely knit) seams.
I think that's a good characterization!
Basically tRPC lets you define a router containing all your endpoints in a single structure. Then you can import the type definition of your router and make typed API calls without needing to wire everything together with types.