How to work with libraries like io-ts, Runtypes and Zod to parse all incoming & outgoing data in your applications type safely.
Press enter or click to view image in full size
Everyone knows that validating user input is the cornerstone of all web programming. In fact, all data coming into (and perhaps data that is leaving leaving) your software should be validated. So what’s this mockery of parsing it instead? What’s this parse, don’t validate (you might want to read that sometime later) mumbo jumbo?
Let’s start from a validation example.
Let’s grab a popular JavaScript validation library like yup. Note that we might as well use other popular libraries like joi or a JSON validator like ajv instead, the point we are making would still stay the same. (EDIT: due to some feedback, there’s an appendix section on ajv in the end)
The above code does a good job of validating data and ensuring it’s valid according to our schema. We have a good chance of creating a…