Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

As someone who never jumped onto the TypeScript hype-wagon, what is this for? Is this something like clojure.spec by for TypeScript so you can do runtime validation of data instead of compile-time validation?

Basically joi (https://joi.dev/api/?v=17.13.3) but different in some way?



I think the killer feature of Zod is type inference. Not sure if Joi has support for it yet but you can take a zod schema and wrap it in `z.infer` to get the typescript type.

Personally I use zod in my API for body validations, it's super nice to write the schema then just use `type Body = z.infer(schema)` to get the TS type to use inside the code.


That's table stakes for this niche.


> Is this something like clojure.spec by for TypeScript so you can do runtime validation of data instead of compile-time

not really "instead", more like "in addition to". Even if your code compiles, if you are receiving data, e.g., via API, then you need to check that it actually conforms to the type/schema you expect. What is run is JS, so it, sadly, won't just crash/error if an object that is supposed to be of `type Cat = {name: string, ownerId: number}` lacks an `ownerId` at runtime.

Have you used Pydantic in Python? It's like that, but feels worse, IMO lol. I say this because Pydantic fits into writing Python code much more naturally than writing Zod stuff fits into writing TypeScript, IMO.


I've not used either, but it appears to be similar to JOI, yes.

The main distinction is that ZOD allows you to extract a TypeScript type from your schema. This means you get both compile-time and run-time type checking.


Correct on the part of it being a runtime validation of data library (I can't as easily speak to whether or not it is similar to joi, never used it)


yep.

Typescript is build-time validation, but in the end TS is "just JS"

Zod provides runtime validation (and also works well with TS)


Deepkit.io has cool validations in runtime based on TS, but it is whole another level.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: