3 ms·
I don't disagree with anything you are saying. However, what is or isn't the goal of a language is subject to change. Libraries like Zod are trying to filling
by lf-non 4y ago
I don't disagree with anything you are saying.
However, what is or isn't the goal of a language is subject to change. Libraries like Zod are trying to filling a gap in js, sure. But we are arguing that that gap is better filled by the typescript - if that requires expanding its goal or doing things that don't fit in current scope - so be it.
As to why it is better: Currently using zod requires that the author of the types uses zod's API. If they didn't anticipate that the types they are writing would need runtime checks, or prefer some other schema validation library than the one you prefer - as a consumer you need to now redefine all of these types using zod and keep them in sync. Compiler can help, sure but its still quite some work.
If typescript supported this natively, you could import some random library and use its types for runtime validation - that is not possible today, and it can't be possible until
ts has first class runtime type validation.
People would also not have to learn the ts syntax and then also the zod api to achieve it.
Languages like dart demonstrate that this is practical.