Live data from Hacker News

Zod 4

zod.dev

201–210 of 260 posts

Re: Zod 4

#201
post #14
post #7

Seeing an announcement for a new version of some typescript library I've never heard of shoot to the top of the front page makes me feel extremely out of touch with mainstream dev.

What do you use for validation in TS? Anyone who deals with data should be validating/parsing it.

Effect Schema (the next incarnation of fp-ts/io-ts) is my go-to for parsing external data in TypeScript, and I heavily recommend it.

Re: Zod 4

#202

Hopefully someone can compare Zod4 to TypeBox. Last I looked, the nice thing about TypeBox was that is _was_ JsonSchema just typed which was nice for interoperability.

I was using TypeBox but switched to Zod. I like TypeBox but I found I don't actually need my schema to be a JSON Schema and the one time I did want a JSON Schema it was hard to get actual JSON back out of TypeBox.

The thing I like about Zod is the "refinements" and "transforms" and the new "overwrite" in Zod 4 was just what I wanted.

TypeBox does have a transform (https://github.com/sinclairzx81/typebox?tab=readme-ov-file#t...) but you can't transform and then apply more validations and then maybe another transform, etc. For example, I like to trim strings before checking length.

Re: Zod 4

#203
post #72

But how is the below possible - doesn't it need to include most of the TypeScript compiler? Does it compile the type definitions to some kind of validation structure (like how a compiled regex works) and then use just that? - Zero external dependencies - Works in Node.js and all modern browsers - Tiny: 2kb core bundle (gzipped)

The TypeScript compiler is only needed during development, the compiled JavaScript code contains no TypeScript-specific logic. Zod’s validation is entirely JavaScript-based, relying on simple checks (e.g., typeof, regexes, comparisons). Also, the 2kb bundle just for the zod/v4-mini package, the full zod/v4 package is quite large.

5.36kB is not "quite large". It's pretty reasonable, esp. if you're only running it on the server.

Re: Zod 4

#204
post #90

Earlier quoted context omitted.

Can you elaborate?

It defines yet another way to declare schemas in a way that's not reusable. ArkType mostly uses TypeScript's, so, it feels more natural.

That's going in the wrong direction IMO. TypeScript checks types only, not business logic. Zod does both.

Re: Zod 4

#205
Defining schemas in zod and using z.infer to get my types is just lovely, thank you!

Re: Zod 4

#206

One decision that seems dubious to me is the zod/v4-mini import. I suspect that this will actually increase bundle sizes across the ecosystem. The docs specifically say "zod/v4 is still recommended for the majority of use cases", so application developers will use it. Library authors will think to themselves, "but I want to enable my library to be used by those with uncommonly strict bundle size requirements", and so…

Library authors should only import from `core`, which is used by both v4 and v4-mini.

ref: https://zod.dev/library-authors?id=how-to-support-zod-and-zo...

Re: Zod 4

#207

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…

A heartfelt thank you for not breaking the world like many other libraries do!

Breaking changed in fundamental but auxiliary libraries are so painful in the world of frontend development that it's not even funny anymore.

Re: Zod 4

#208
post #35

Congratulations to the Zod team on the new release. At the risk of sounding overtly negative, I can't help but shudder when I think about the number of breaking changes outlined in the migration guide. For projects that rely heavily on Zod, it feels like a daunting task ahead—one that will demand a lot of developer attention and time to navigate. Having maintained a few frontend projects that are 4-5 years old at wor…

I am 100% in agreement here. I operate a couple large Next.js apps and in the last year we've had to deal with Next.js 14 -> 15 which introduced a ton of breaking cache changes, Next.js pages -> app router, React 18 -> 19, Eslint 8 -> 9, and Tailwind 3 -> 4. It's honestly been a nightmare, and I wish I had just built in Django instead. The Tailwind 3 -> 4 migration was probably among the most painful, which I was not…

OPINION WARNING

Eslint 8 → 9 was not just incredibly painful with a shock wave that still propagates through the industry, but it was also totally useless

Re: Zod 4

#209

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…

> The approach I ended up using is analogous to what Golang does. In essence a given package never publishes new breaking versions: they just add a new subpath when a new breaking release is made. In the TypeScript ecosystem, this means libraries can configure a single peer dependency on zod@^3.25.0 and support both versions simultaneously by importing what they need from "zod/v3" and "zod/v4". It provides a nice opt-in incremental upgrade path for end-users of Zod too.

This is extremely sensible. And it means you can provide security updates for older versions, just all in the same codebase's releases.

Re: Zod 4

#210
post #147

Earlier quoted context omitted.

People wouldn't change to the new one, because names are extremely sticky, so what's the point?

If they need the new one, they will switch to it. And you have the right to drop support for the old one after a while (hopefully giving everyone the time to migrate).

> If they need the new one, they will switch to it.

I already gave my argument on why this won't happen. People stick to what they know and trust. They don't change because there is some other thing that is supposedly better. It has to be 10x better before people will migrate off one thing to another. If you want to do incremental improvements to a thing, then you'll have to do incremental improvements to that thing.

Post reply on HN