2 ms·
Zod is really useful when you have complex data coming in and you're not sure what the structure may be at runtime. Zod helps you prove really quickly that the
by striking 3y ago
Zod is really useful when you have complex data coming in and you're not sure what the structure may be at runtime. Zod helps you prove really quickly that the data coming in is of the appropriate shape.
Now, it's already possible to take certain kinds of objects and narrow their types using plain TypeScript and have all kinds of really solid guarantees about how you're checking the data (and the checks are always going to be as fast as the types will allow, which is great). But Zod is important for being able to take unstructured data and ensure it's compatible with your desired types, in a flexible way, at a cost to runtime speed.
I don't think the Zod stuff is going to find its way into the TypeScript language / standard library. There's very little actual codegen being done in TypeScript (sugar around enums notwithstanding), most of the work to convert it to JS is just checking the types and then stripping them. What you might see instead are improvements to type narrowing.