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

Except for the fact that usually there is not just one single typescript agent working within itself, for which you don't need validation. There are many cases in which you need to verify some object, anything that does not come from your code i would argue is untrusted, I come across this almost daily, it would be absolutely fantastic to just have a way to check does this object conform to this type? Instead, i need to use some external dependency, effectively duplicate my type definitions and add yet another place to introduce bugs.


Just use a run-type transformer like typia, hooked right into typescript-compile. Get your runtime type validators generated from nothing but the typescript definitions.

Alternatively, use a runtime validator the provides good type inference out of the box so you're still only declaring your types once.


I would recommend `zod` as a good typescript schema runtime validation library as well. It does require strict type checking to be on however.


I use zod but it's a workaround. I use non standard syntax to define types.

If typescript emitted type information, we'd be able to automatically get runtime validation at the boundaries of our apps.


Alternatively, io-ts is more performant and has been around for a while longer. Although it does have a more functional interface.


I like typia for doing codegen basically in the way this request is asking: it hooks into the typescript API to create runtypes from plain old typescript




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

Search: