Skip to content
masterclass Buddy

Zod · Function

z.optional

z.optional creates a schema that accepts undefined in addition to values accepted by another schema. It is also available as the .optional() method.

Last updated

Syntax

z.optional(schema)
// or
schema.optional()

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • z.nullable
  • z.nullish
  • z.exactOptional
  • ZodOptional
  • .optional()
  • .unwrap()

Source: Defining schemas | Zod. Checked 2026-11-03.