Earlier quoted context omitted.
We have an enormous number of backend-only Zod schemas that are used as part of our data pipelines; so it doesn't seem like something that only exists to solve SPA problems.
If it’s backend only why do JSON shapes need to be continually checked? Can’t you serialize higher level classes or use the database?
Zod 4
251–260 of 260 posts
Re: Zod 4
#252Earlier quoted context omitted.
Is there any advantage to this approach over publishing a separate "zod4" package? That would be just as opt-in and incremental, not bloat download sizes forever, and make it easier to not accidentally import the wrong thing.
Ecosystem libraries would need to switch from a single peer dependency on Zod to two optional peer dependencies. Despite "optional peer dependencies" technicall being a thing, its functionally impossible for a library to determine which of the two packages your user is actually bringing to the table. Let's say a library is trying to implement an `acceptSchema` function that can accepts `Zod3Type | Zod4Type`. For star…
I am still curious about the `zod4` idea though. Any thoughts on adding an `__api_version` type of property to distinguish on to all of zod's public types? Perhaps it's prohibitive code-size wise but wondering if it's possible somehow. Then downstream libraries could differentiate by doing the property check.
Just wanted to share the idea but the current state seems ok too.
Re: Zod 4
#253Re: Zod 4
#254The little animation that highlights what section you are reading currently is beautiful
Re: Zod 4
#255Zod is a lot better than some of the alternative solutions I've seen. That said, the need for this sort of explicit validation always felt like a failure of where modern web development has taken us. It's so frustrating how full-stack development requires so many ways of describing the same shapes: JS input validation, Swagger for API definition, server-side input validation, ORM for schema conformance, and TypeScrip…
We use drizzle + Hono + client with zod. So the entire chain from ui to client to server to DB follow same validation and shape.
Re: Zod 4
#256Re: Zod 4
#257Author here, AMA! Regarding the versioning: I wrote a fairly detailed writeup here[0] for those who are interested in the reasons for this approach. Ultimately npm is not designed to handle the situation Zod finds itself in. Zod is subject to a bunch of constraints that virtually no other libraries are subject to. Namely, the are dozens or hundreds of libraries that directly import interfaces/classes from Zod and use…
I saw your tweet about cracking type inference for recursive schemas. It seems like the solution to this problem is pretty straightforward and simple. Was the solution really as simple as using a getter, or is there some additional complexity that I am failing to grok?
Re: Zod 4
#258Earlier quoted context omitted.
I saw your tweet about cracking type inference for recursive schemas. It seems like the solution to this problem is pretty straightforward and simple. Was the solution really as simple as using a getter, or is there some additional complexity that I am failing to grok?
the solution is to avoid TypeScript eagerly validating the object's value type. eager validation breaks cyclic references.
https://github.com/mary-ext/atcute/blob/596e023bcb490b16d09a...
Re: Zod 4
#259Earlier quoted context omitted.
We use drizzle + Hono + client with zod. So the entire chain from ui to client to server to DB follow same validation and shape.
How do you use the same validation for drizzle and zod? I have been writing duplicate schemas and hoping they match...