Skip to main content

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 the rest parameter to allow additional elements:
Alternatively, use the .rest() method:

Methods

rest()

Define a schema for additional elements beyond the fixed items.
Signature:
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