Live data from Hacker News

Zod 4

zod.dev

181–190 of 260 posts

Re: Zod 4

#181

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…

Just would like to say I really appreciate your consideration of releasing breaking changes. I know not all libraries can employ your methodology but I wish many more of them would, as a frontend platform engineer.

Re: Zod 4

#182
post #9

Earlier 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.

And thus is born the 15th IDL for cross language API calls...

Re: Zod 4

#183

With 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.

The next step is to click the project logo in the top left.

Re: Zod 4

#184
All 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

#185
post #184

All 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".

there's an 'Intro' link under the 'Documentation' header on the left side

Re: Zod 4

#186
post #184

All 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".

[deleted]

Re: Zod 4

#187
post #140

Earlier 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…

> The frontend and the backend are generally different domains

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

#188
post #184

All 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".

"TypeScript-first schema validation with static type inference"

Re: Zod 4

#189
post #84

Earlier 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?

Sure, and then only 10% of your use cases contain easily exploitable vulnerabilities.

Re: Zod 4

#190
post #39

> 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.

This isn't an npm exclusive issue. A dependency having some other transitive deps also depend on an older version is a problem that happens in literally every other ecosystem. If anything, npm gives you more escape hatches by actually allowing you to run multiple versions concurrently if you need to or selectively overriding parts of your transitive dependency graph.

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).

Post reply on HN