colinhacks / zod

TypeScript-first schema validation with static type inference
https://zod.dev
MIT License
33.09k stars 1.15k forks source link

PanelOn: z.coerce.boolean(), is generating an optional field PanelOn. How can we require it? #3612

Open realtebo opened 2 months ago

realtebo commented 2 months ago
Payload: z.object({
        PanelOn: z.coerce.boolean(),
]}

having the previous object definition, if we pass a Payload withput the field PanelOn, it will be assumed as boolean false.

How can I force boolean to be first required and then coerced to javascript boolean only if they are present in the object?

I must ensure that validation DO NOT PASSES if field is missing