zod
zod copied to clipboard
Feature request. Enable or disable .strict() by argument
For the staging environment, I want to provide additional protocol validation with strict parsing, but it can break something on production, so I see the next solution
.strict(process.env.NODE_ENV === 'development')
and it gives
.strict()— strict mode enabled.strict(true)— strict mode enabled.strict(false)— strict mode disabled
Is it hard to implement?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Please do not stale this issue :) I hope that PR will be merged soon. @brunocrosier thank you for participating.
Is this what you are looking for? https://github.com/colinhacks/zod/pull/1484#issuecomment-1284640538
@JacobWeisenburger hi
const rawSchema = z.object({ ... });
const schema = process.env.NODE_ENV === 'development' ? rawSchema : rawSchema.strict()
I have a lot of different schemas and don't want to create add condition before each.
Does this work for you?
function makeSchemaStrict<ObjSchema extends z.ZodObject<z.ZodRawShape>> ( objSchema: ObjSchema ) {
return process.env.NODE_ENV === 'production' ? objSchema : objSchema.strict()
}
@JacobWeisenburger thank you for participation, I understand how to improve it, but it's look less natural and also in this case I need to recheck generation of TS types based on schema