Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

AFAIK typescript interfaces don't exist at runtime, so you can't validate incoming JSON with type any.

Also you can't really hand a third party a typescript interface and tell them to conform with that.

And finally, I would imagine a good schema could enforce more things like the length of identifiers, whether a number can be negative, etc.



> AFAIK typescript interfaces don't exist at runtime, so you can't validate incoming JSON with type any.

That's mostly true, but some projects exist that allow a subset of interfaces to be used at runtime:

- https://github.com/gcanti/io-ts

- https://github.com/fabiandev/ts-runtime

- https://github.com/codemix/flow-runtime

- Or just manual assertions: https://gist.github.com/JohnWeisz/beb7b4dadc512be30ce6c7c1e4...




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

Search: