Author 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…
Zod 4
181–190 of 260 posts
Re: Zod 4
#182Earlier quoted context omitted.
But that’s the whole point of something like this. You do it once and dynamically generate everything else downstream. So change it once in the zod schema and it propagates with type checking through your entire app. The zod schema becomes the source of truth.
Does zod really support that? What if the code base start out with a go backend and a TS/JS component is only added later? It would be nice if the source of truth was a bit more language agnostic.
Re: Zod 4
#183With yet another exciting new release of something reaching the top of HN, I would just like to urge devs to put a description of the project they're actually releasing and a link to the page describing the project in the release announcement. These announcements could be a valuable touchpoint for you to reach a whole new audience, but I can't remember a single one that starts with something like "exciting new releas…
I came here to say this. I clicked on the link and had no idea what this was about.
Re: Zod 4
#184Re: Zod 4
#185All that text. So, so much text and not one single (maybe there was, but I fell asleep), not one single "Let me tell you what Zod is" paragraph. Lots of "Zod 4 is better than Zod 3" and "Here's what we pulled back, out, in, from Zod 2".
Re: Zod 4
#186All that text. So, so much text and not one single (maybe there was, but I fell asleep), not one single "Let me tell you what Zod is" paragraph. Lots of "Zod 4 is better than Zod 3" and "Here's what we pulled back, out, in, from Zod 2".
Re: Zod 4
#187Earlier quoted context omitted.
You use Zod to define all the schemas and types used in "your core domain". It is the base layer tool of your business logic and models, and for defining your interfaces. And yes it makes it possible to share all of this between the frontend and backend, which is a tremendous improvement in both correctness and in development productivity. You don't get anything remotely like this in any other backend frontend combo.
I get the wish to have that, but IMO, it's a flawed approach. The frontend and the backend are generally different domains. Initially, their model may look alike, but they will probably differs during the lifetime of the project as they serve different needs. That's why the shape of the data stored in the DB differs from the one involved in business logic, which differs from the DTOs, which can differs from the objec…
It is not a flawed approach, it's an important need for most web apps. Zod is a validation library, the whole purpose of is to define structures that can safely be shared across domains.
Re: Zod 4
#188All that text. So, so much text and not one single (maybe there was, but I fell asleep), not one single "Let me tell you what Zod is" paragraph. Lots of "Zod 4 is better than Zod 3" and "Here's what we pulled back, out, in, from Zod 2".
Re: Zod 4
#189Earlier quoted context omitted.
let someArray = [1, 2, , 4]; console.log(as.numbers(someArray) === someArray); // => true for (let number of numbers) { // This should be safe because I know everything in the array is a number, right? console.log(number.toFixed(2)); // => TypeError: number is undefined } I mean, it's probably fine if you're only ever getting your data from JSON.parse(). But I would hesitate to use this in production.
> I mean, it's probably fine if you're only ever getting your data from JSON.parse(). So 90% of use cases?
Re: Zod 4
#190> To simplify the migration process both for users and Zod's ecosystem of associated libraries, Zod 4 is being published alongside Zod 3 as part of the zod@3.25 release. [...] import Zod 4 from the "/v4" subpath npm is an absolute disaster of a dependency management system. Peer dependencies are so broken that they had to make v4 pretend it's v3.
What package management system has a solution to this? Even so called "stable" platforms like Maven deal with this nonsense by publishing new versions under a new namespace (like Apache Commons did from v2 to v3).