Skip to main content

.nullable()

Makes a schema accept null in addition to its base type.

Type Inference

The .nullable() modifier affects both input and output types:

Unwrapping

You can remove the nullable wrapper using .unwrap():

In Object Schemas

.nullable() does not make a field optional in objects. The field must still be present, but can be null.

.nullish()

A convenience method that combines .optional() and .nullable(), making a schema accept null, undefined, or the base type.

Type Inference

In Object Schemas

Use Cases

  • .nullable(): Use for database fields that can be NULL but must be present
  • .nullish(): Use for optional fields that could also be explicitly set to null

Chaining Examples

Implementation Note