▲ | tomjakubowski 2 days ago | |
Libraries like runtypes, zod, et al. market themselves as validation libraries, but they function as parsing libraries in the sense this article means: with them you "parse" untyped POJOs at the I/O boundary and get typed values (or a raised exception) out the other end. Typescript language features like branded types, private constructors can make it so those values can only be constructed through the parse method. They're really not much different, in terms of type safety*, from something like Serde. *: they are of course different in other important ways -- like that Serde can flexibly work with all kinds of serialized formats. | ||
▲ | nayajunimesh 2 days ago | parent [-] | |
We actually use the idea of branded types in one of the validators (iso8601), and I also understand that it doesn't replace fully transformed values. https://github.com/nimeshnayaju/valleys?tab=readme-ov-file#i... |