Skip to main content

Basic Usage

Create a schema that requires the input to satisfy all provided schemas.

Signature

ZodType
required
The first schema to intersect.
ZodType
required
The second schema to intersect.

Convenience Method

Use the .and() method as shorthand:

Object Intersections

Merge object shapes:
For objects, prefer .extend() over .intersection() for better type inference and performance.

Type Conflicts

Intersecting incompatible types creates impossible schemas:

Overlapping Object Properties

When objects have the same property:
To handle this, use union types:

Array Intersections

Intersecting arrays merges element constraints:
Incompatible element types create invalid schemas:

Primitive Intersections

Intersecting primitives with refinements:

Type Inference

Multiple Intersections

Chain multiple .and() calls:

Common Patterns

Mixins

Combining Constraints

Partial Updates

Intersection vs Union

Limitations

Intersections have limitations with:
  • Primitive type conflicts (e.g., string & number)
  • Incompatible array element types
  • Overlapping object properties with different types
For object merging, prefer:
  1. .extend() for adding properties
  2. .merge() for combining objects (deprecated, use .extend(other.shape))
  3. Manual object construction for complex cases