Hacker News new | past | comments | ask | show | jobs | submit login

Then you're maintaining two definitions - typescript ones and json schema ones. But thanks for the idea :)



Well, you could have one or the other and then just convert a schema to an Interface [1], or vice versa [2].

The reason I like schema-first is because a schema allows you to be way more strict about what's accepted in most cases, e.g. validating an entry via RegEx. It tends to make APIs safer and runtime errors more clear.

[1] https://github.com/bcherny/json-schema-to-typescript

[2] https://github.com/YousefED/typescript-json-schema


You could write the runtime definition and extract the static types from that https://github.com/gcanti/io-ts


thanks for the link - i've never seen that before :)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: