4 ms·
Zod [0] is my favorite TypeScript library. It really helps ensure that all the little nooks and crannies of your application can be properly typed. An example
by shepherdjerred 2y ago
Zod [0] is my favorite TypeScript library. It really helps ensure that all the little nooks and crannies of your application can be properly typed.
An example is receiving API response with `fetch`. Normally you'd cast the response to the expected type, but it's not uncommon for you to misunderstand what the API can return or for the API to be changed/updated. Zod lets you verify your types at runtime so that if your API returns something unexpected then you can act on it.
This is really useful anytime you're interacting with I/O or user input. For example, I've used Zod for: loading from JSON files, reading from local storage, parsing URL params, or validating form input.
[0]: https://zod.dev/ https://zod.dev/
- threatofrain 2y agoI'd also say checkout Valibot. It has a nice composable pipe¹ API so a small handful of atoms is expressive over a lot of type needs. It's also more petite and performant. const natural = pipe(string(), transform(atoi), minValue(0)) const percent = pipe(natural, maxValue(100)) [1]: https://valibot.dev/guides/pipelines/ https://valibot.dev/guides/pipelines/