Basic Usage
Create a tuple schema with a fixed number of elements, each with its own type.Signature
ZodType[]
required
Array of schemas, one for each tuple element.
ZodType
Optional schema for additional elements beyond the fixed items.
string | ZodTupleParams
Optional error message (string) or configuration object.
Fixed-Length Tuples
Define tuples with a specific number of elements:Variable-Length Tuples
Use therest parameter to allow additional elements:
.rest() method:
Methods
rest()
Define a schema for additional elements beyond the fixed items.ZodType
required
Schema to validate additional elements against.
Empty Tuples
Create a tuple with no elements:Type Inference
Common Patterns
Coordinates
Key-Value Pairs
Function Returns
CSV Row
Refinements
Add custom validation logic:Transformations
Transform tuple values:Tuple vs Array
Related
- z.array() - For variable-length arrays with uniform types
- z.object() - For named properties
- z.record() - For dynamic key-value pairs