4 ms·
zod and yup both give runtime types and they're great. They can also export typescript types. But as far as I understand it, typescript is a layer "on top of" j
by elliottkember 3y ago
zod and yup both give runtime types and they're great. They can also export typescript types. But as far as I understand it, typescript is a layer "on top of" javascript that does not exist at runtime. It all gets stripped and you're left with valid javascript. So no – I doubt it. They exist in different worlds.
- btown 3y agozod or yup gets you quite a bit of the way there in practice - when you would reach for a Typescript type, making it in zod instead is more verbose but gives that runtime layer. But for those who actually want full-stack non-stripped runtime type reflection based on Typescript syntax alone... https://deepkit.io/ https://deepkit.io/ - https://deepkit.io/blog/introducing-deepkit-framework https://deepkit.io/blog/introducing-deepkit-framework - is a really promising and cool project. It patches the typescript compiler (which pointedly considers runtime type information out of scope) with its own type compiler that emits a bespoke bytecode that is executed in a bespoke VM to communicate runtime type information to both server and client as needed. https://docs.deepkit.io/english/runtime-types.html https://docs.deepkit.io/english/runtime-types.html And from that baseline, there are very cool things you can do like an ORM entirely based on type annotations https://docs.deepkit.io/english/database.html https://docs.deepkit.io/english/database.html or strongly-typed RPCs https://docs.deepkit.io/english/rpc.html https://docs.deepkit.io/english/rpc.html . It's very much in the alpha stage, but it's really well thought out - there's a tremendous degree of care the developer is taking towards code cleanliness and developer experience. I'm torn between wishing this project to have a fully funded team and take the world by storm, vs. "letting them cook" so to speak and seeing the developer experience unfold organically. Either way, it's a breath of fresh air into the Typescript ecosystem!