Hacker News new | ask | show | jobs
by mooreed 1029 days ago
Does anyone know of a typescript translation for each of those validation models?

Or maybe even a way to discover related statically typed definitions based on the validation rules?

It would be really nice to not define parts of a data model that provide little to no business value - but where you can easily “stub your toe”.

4 comments

use quicktype: https://quicktype.io/
Awesome tool, thank you for sharing. I made use of it already!
Most languages have some code generation tool requiring a compile step, but most of the specs in here change infrequently enough you can just do it once and commit to VC. I personally have a use case where I modify the Meltano (ETL tool) spec at runtime and use a generated scheme to validate reads and writes to the file, helping catch bugs early.
You could use this[0] package but you would need to download the schema first into a folder say "schemas" and then add a build step as a script in your package.json '"compile-schemas": "json2ts -i schemas -o types"' to export to a "type" folder

[0] json-schema-to-typescript

If it's a one-off you can just use http://borischerny.com/json-schema-to-typescript-browser/ or https://transform.tools/json-schema-to-typescript (they both use the same library).
I've been asking chatgpt to do it for me.