←back to thread

Zod v4 Beta

(v4.zod.dev)
175 points mycroft_4221 | 3 comments | | HN request time: 0s | source
Show context
cianuro_ ◴[] No.43669756[source]
I completely understand TypeScript, Zod not so much. The context here is performance.

My understanding is that Zod performs synchronous operations to validate the schemas. Something about "using the tool correctly" resonates here. Maybe don’t validate very large and nested schemas frequently and things like that.

But I can’t help but think it is adding another layer of potential footguns that you have to be mindful about. Maybe the benefits outshine the risks in disciplined teams that understand both the tool and the runtime. However I can’t help but think about the less disciplined teams abusing Zod and then wondering why things are slow.

replies(2): >>43670282 #>>43672042 #
1. sureIy ◴[] No.43670282[source]
> I completely understand TypeScript, Zod not so much

Different tools. I only use TS but once you add external data to the mix you cannot escape `any` and `unknown` — so what you do is use `as`. Congrats, your types are now useless.

Zod would close that gap as it enforces types on external resources (e.g. `fetch` or `readFile`)

replies(1): >>43671534 #
2. gavinray ◴[] No.43671534[source]
That's not necessarily true.

You can write type assertion functions that validate the input is a given shape.

In theory, you'd use these type assertion methods at any API boundaries a single time for external inputs/outputs in a "Parse, Don't Validate" approach to cover your bases.

replies(1): >>43671678 #
3. mijamo ◴[] No.43671678[source]
Soooo exactly what Zod is doing?