Skip to main content

Basic Usage

Type Signature

string | $ZodBooleanParams
Optional error message (string) or configuration object

Behavior

z.boolean() only accepts literal true and false values. It does NOT perform type coercion:

Type Coercion

If you need to accept truthy/falsy values, use coercion:

Usage with Optional

Usage with Nullable

Default Values

Custom Error Messages

TypeScript Type

Refinements

While uncommon, you can add refinements to boolean schemas:

See Also