News for hackers. Stuff that matters.
Re:tRPC – Move Fast and Break Nothing. End-to-end typesafe A... by scriptsmith on Saturday August 12, 2023 @07:58AM (#37099295)
Is there some trick to doing validation of request data using this process? That's a valuable part of using something like tRPC, JSON Schema + type generation, zod, etc.
Re:tRPC – Move Fast and Break Nothing. End-to-end typesafe A... by jitl on Saturday August 12, 2023 @08:12AM (#37099393)
We use an internal validator library that we infer request types from. It’s similar to Zod (but also predates it by a year).

I’ve also spent some time on a Typescript type to X compiler. My first prototype is open source and targets Thrift, Proto3, Python, and JSON schema: https://github.com/justjake/ts-simple-type/tree/main/src/com...

I’m not happy with the design decision in that codebase to try to “simplify” Typescript types before compiling, and probably won’t continue that implementation, but we have a few internal code generators that consume TS types and output test data builders and model clases we use in production.

I want to open source some of those bits but haven’t found the time.

Re:tRPC – Move Fast and Break Nothing. End-to-end typesafe A... by chaos_emergent on Saturday August 12, 2023 @08:51AM (#37099666)
Deepkit is a fantastic solution for this. It uses a compilation step to inject metadata about types into plain JS.

https://deepkit.io/

Re:tRPC – Move Fast and Break Nothing. End-to-end typesafe A... by jitl on Saturday August 12, 2023 @09:28AM (#37099953)
Deepkit looks really cool, but it’s so complex on the inside and leverages a forked/patched Typescript and requires full typecheck before emit.

What happens if the Deepkit guy retires? What if I want to run my code without waiting for 11 minutes of typechecking? What if there’s a bug somewhere in there?

There’s way too much risk for me to consider Deepkit for production.