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:Array Intersections
Intersecting arrays merges element constraints: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
For object merging, prefer:.extend()for adding properties.merge()for combining objects (deprecated, use.extend(other.shape))- Manual object construction for complex cases
Related
- z.union() - For OR logic (alternative types)
- z.object() - For object schemas with
.extend() - z.discriminatedUnion() - For tagged unions