zod icon indicating copy to clipboard operation
zod copied to clipboard

Option for strict objects by default

Open cdtut opened this issue 2 months ago • 4 comments

With deeply nested object .strict must be added on every .object to check all keys but is easy to forget that. Option should be on parse function to check all objects strict by default. Could disable that on a particular object with z.object().strict(false). As example joi allows such option.

cdtut avatar Apr 18 '24 00:04 cdtut

This is coming in Zod 4.

colinhacks avatar Apr 18 '24 01:04 colinhacks

Is there roadmap to follow what else is coming in zod 4?

cdtut avatar Apr 18 '24 01:04 cdtut

Not currently, since it's still in flux, but I'll be working to communicate this more completely soon.

colinhacks avatar Apr 18 '24 05:04 colinhacks

I suggest something like parser = z.parser(options) to pass options like strictObjects: true so you have reusable parser object you can use all over project and use it like parser.parse(schema, object) or schema.parse(parser, object). Can such design work?

cdtut avatar Apr 18 '24 16:04 cdtut