News for hackers. Stuff that matters.
Re:Designing the perfect TypeScript schema validation library by eyelidlessness on Thursday March 12, 2020 @06:27PM (#22562584)
This is basically that but in the opposite direction. It also has the advantage of being able to express validations that you can't express in the type system.
Re:Designing the perfect TypeScript schema validation library by colinmcd on Thursday March 12, 2020 @06:32PM (#22562630)
I should point out that there's nothing in Zod (yet) that isn't expressible in Typescript. I'll eventually get around to doing string/numerical validations (`.isEmail()`, etc) that go beyond TS but currently all functionality has an equivalent in TS.
Re:Designing the perfect TypeScript schema validation library by randomchars on Thursday March 12, 2020 @06:30PM (#22562613)
Do you have an example of the kind of validation couldn't be expressed in the type system?
Re:Designing the perfect TypeScript schema validation library by root_axis on Thursday March 12, 2020 @06:32PM (#22562627)
Min or max length of an input. Any type of string validation like email or something similar that's validated via regex.
Re:Designing the perfect TypeScript schema validation library by eyelidlessness on Thursday March 12, 2020 @06:46PM (#22562770)
root_axis gave some good examples. Also types like `int` or `decimal` (which you can also pair with branded static types, but they don't actually guarantee anything other than their name. Really any kind of refinement you can imagine on primitive types.