▲ | kentonv 4 days ago | ||||||||||||||||
I really want to bake in some sort of support for generating type checks based on TypeScript types... so then your schemas are just TypeScript. Not sure why this doesn't seem to be a common practice TBH, might be missing something. | |||||||||||||||||
▲ | crabmusket 4 days ago | parent | next [-] | ||||||||||||||||
We built our own in-house RPC interface definition pipeline where the schemas are just typescript types, looking very similar to the example in your post
We parse the typescript to JSON Schema, then use that to generate runtime validation across both JS implementations and other languages.Typescript is a really nice IDL. I didn't want to hitch our wagon to something else like typespec.io even if that would have given us more things out of the box. | |||||||||||||||||
▲ | ryanrasti 4 days ago | parent | prev | next [-] | ||||||||||||||||
> Not sure why this doesn't seem to be a common practice TBH, might be missing something. Yeah... I've been deep in this problem space myself. The two big points of friction are: 1. Requiring a build-step to generate runtime code from the TS types 2. TS doesn't officially support compiler transforms that do it That said, the two most promising approaches I've found so far: 1. https://github.com/GoogleFeud/ts-runtime-checks -- it does exactly what you describe 2. https://arktype.io/ -- a very interesting take on the Zod model, but feels like writing native Typescript Congrats on the launch, really exciting to see a way to get capabilities into the JS ecosystem! | |||||||||||||||||
▲ | stavros 4 days ago | parent | prev [-] | ||||||||||||||||
That would be great, would these checks run at deserialization time? They'd probably need to, as you wouldn't want to assume that the stuff coming through the network is of a specific type. | |||||||||||||||||
|