Tuple<Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]export declare namespace Tuple {
/**
* Constraint for the readonly array of element schemas used to define a
* fixed-length `Tuple` schema.
*
* @category utility types
* @since 3.10.0
*/
export type type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements = interface ReadonlyArray<T>ReadonlyArray<Constraint>
type type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Type_<Tail, readonly [...Out, (T | undefined)?]> : Type_<Tail, readonly [...Out, T]> : Out : Out
Type_<
function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements,
function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Out extends interface ReadonlyArray<T>ReadonlyArray<any> = readonly []
> = function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ?
function (type parameter) HeadHead extends { readonly "Type": infer function (type parameter) TT } ?
function (type parameter) HeadHead extends { readonly "~type.optionality": "optional" } ? type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Type_<Tail, readonly [...Out, (T | undefined)?]> : Type_<Tail, readonly [...Out, T]> : Out : Out
Type_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT?]>
: type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Type_<Tail, readonly [...Out, (T | undefined)?]> : Type_<Tail, readonly [...Out, T]> : Out : Out
Type_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT]>
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
/**
* Computes the decoded tuple type for a tuple element schema array.
*
* **Details**
*
* Each element contributes its decoded `Type`; optional element schemas produce
* optional tuple positions.
*
* @category utility types
* @since 3.10.0
*/
export type type Tuple<Elements extends Tuple.Elements>.Type<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Type_<Tail, readonly [(T | undefined)?]> : Type_<Tail, readonly [T]> : readonly [] : readonly []
Computes the decoded tuple type for a tuple element schema array.
Details
Each element contributes its decoded Type; optional element schemas produce
optional tuple positions.
Type<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Type<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = type Tuple<Elements extends Tuple.Elements>.Type_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Type_<Tail, readonly [...Out, (T | undefined)?]> : Type_<Tail, readonly [...Out, T]> : Out : Out
Type_<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Type<E extends Tuple.Elements>E>
type type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Iso_<Tail, readonly [...Out, (T | undefined)?]> : Iso_<Tail, readonly [...Out, T]> : Out : Out
Iso_<
function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements,
function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Out extends interface ReadonlyArray<T>ReadonlyArray<any> = readonly []
> = function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ?
function (type parameter) HeadHead extends { readonly "Iso": infer function (type parameter) TT } ?
function (type parameter) HeadHead extends { readonly "~type.optionality": "optional" } ? type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Iso_<Tail, readonly [...Out, (T | undefined)?]> : Iso_<Tail, readonly [...Out, T]> : Out : Out
Iso_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT?]>
: type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Iso_<Tail, readonly [...Out, (T | undefined)?]> : Iso_<Tail, readonly [...Out, T]> : Out : Out
Iso_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT]>
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
/**
* Computes the iso tuple type for a tuple element schema array from each
* element schema's `Iso` type.
*
* @category utility types
* @since 4.0.0
*/
export type type Tuple<Elements extends Tuple.Elements>.Iso<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Iso_<Tail, readonly [(T | undefined)?]> : Iso_<Tail, readonly [T]> : readonly [] : readonly []
Computes the iso tuple type for a tuple element schema array from each
element schema's Iso type.
Iso<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Iso<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = type Tuple<Elements extends Tuple.Elements>.Iso_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Iso_<Tail, readonly [...Out, (T | undefined)?]> : Iso_<Tail, readonly [...Out, T]> : Out : Out
Iso_<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Iso<E extends Tuple.Elements>E>
type type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Encoded_<Tail, readonly [...Out, (T | undefined)?]> : Encoded_<Tail, readonly [...Out, T]> : Out : Out
Encoded_<
function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements,
function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Out extends interface ReadonlyArray<T>ReadonlyArray<any> = readonly []
> = function (type parameter) Elements in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Elements extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ?
function (type parameter) HeadHead extends { readonly "Encoded": infer function (type parameter) TT } ?
function (type parameter) HeadHead extends { readonly "~encoded.optionality": "optional" } ? type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Encoded_<Tail, readonly [...Out, (T | undefined)?]> : Encoded_<Tail, readonly [...Out, T]> : Out : Out
Encoded_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT?]>
: type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Encoded_<Tail, readonly [...Out, (T | undefined)?]> : Encoded_<Tail, readonly [...Out, T]> : Out : Out
Encoded_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT]>
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []>Out
/**
* Computes the encoded tuple type for a tuple element schema array.
*
* **Details**
*
* Each element contributes its `Encoded` type; encoded-side optional element
* schemas produce optional tuple positions.
*
* @category utility types
* @since 3.10.0
*/
export type type Tuple<Elements extends Tuple.Elements>.Encoded<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Encoded_<Tail, readonly [(T | undefined)?]> : Encoded_<Tail, readonly [T]> : readonly [] : readonly []
Computes the encoded tuple type for a tuple element schema array.
Details
Each element contributes its Encoded type; encoded-side optional element
schemas produce optional tuple positions.
Encoded<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Encoded<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = type Tuple<Elements extends Tuple.Elements>.Encoded_<Elements, Out extends ReadonlyArray<any> = readonly []> = Elements extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Encoded_<Tail, readonly [...Out, (T | undefined)?]> : Encoded_<Tail, readonly [...Out, T]> : Out : Out
Encoded_<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.Encoded<E extends Tuple.Elements>E>
/**
* Union of all decoding service requirements needed by the tuple element
* schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type Tuple<Elements extends Tuple.Elements>.DecodingServices<E extends Tuple.Elements> = E[number]["DecodingServices"]Union of all decoding service requirements needed by the tuple element
schemas.
DecodingServices<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.DecodingServices<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.DecodingServices<E extends Tuple.Elements>E[number]["DecodingServices"]
/**
* Union of all encoding service requirements needed by the tuple element
* schemas.
*
* @category utility types
* @since 4.0.0
*/
export type type Tuple<Elements extends Tuple.Elements>.EncodingServices<E extends Tuple.Elements> = E[number]["EncodingServices"]Union of all encoding service requirements needed by the tuple element
schemas.
EncodingServices<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.EncodingServices<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.EncodingServices<E extends Tuple.Elements>E[number]["EncodingServices"]
type type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? MakeIn_<Tail, readonly [...Out, (T | undefined)?]> : MakeIn_<Tail, readonly [...Out, T]> : Out : Out
MakeIn_<
function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>E,
function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>Out extends interface ReadonlyArray<T>ReadonlyArray<any> = readonly []
> = function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>E extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ?
function (type parameter) HeadHead extends { "~type.make": infer function (type parameter) TT } ?
function (type parameter) HeadHead extends
{ readonly "~type.optionality": "optional" } | { readonly "~type.constructor.default": "with-default" } ?
type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? MakeIn_<Tail, readonly [...Out, (T | undefined)?]> : MakeIn_<Tail, readonly [...Out, T]> : Out : Out
MakeIn_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT?]> :
type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? MakeIn_<Tail, readonly [...Out, (T | undefined)?]> : MakeIn_<Tail, readonly [...Out, T]> : Out : Out
MakeIn_<function (type parameter) TailTail, readonly [...function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>Out, function (type parameter) TT]>
: function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>Out :
function (type parameter) Out in type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []>Out
/**
* Computes the input tuple type accepted when constructing a tuple value.
*
* **Details**
*
* Each element uses its `~type.make` input type. Optional elements and elements
* with constructor defaults produce optional tuple positions.
*
* @category utility types
* @since 4.0.0
*/
export type type Tuple<Elements extends Tuple.Elements>.MakeIn<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? MakeIn_<Tail, readonly [(T | undefined)?]> : MakeIn_<Tail, readonly [T]> : readonly [] : readonly []
Computes the input tuple type accepted when constructing a tuple value.
Details
Each element uses its ~type.make input type. Optional elements and elements
with constructor defaults produce optional tuple positions.
MakeIn<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.MakeIn<E extends Tuple.Elements>E extends type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> = type Tuple<Elements extends Tuple.Elements>.MakeIn_<E, Out extends ReadonlyArray<any> = readonly []> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? MakeIn_<Tail, readonly [...Out, (T | undefined)?]> : MakeIn_<Tail, readonly [...Out, T]> : Out : Out
MakeIn_<function (type parameter) E in type Tuple<Elements extends Tuple.Elements>.MakeIn<E extends Tuple.Elements>E>
}
/**
* Type-level representation returned by {@link Tuple}.
*
* @category models
* @since 3.10.0
*/
export interface interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements extends Tuple.type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
import SchemaASTSchemaAST.class Arraysclass Arrays {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays,
interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
>
{
readonly "Type": Tuple.type Tuple<Elements extends Tuple.Elements>.Type<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Type: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Tuple.Type_<Tail, readonly [(T | undefined)?]> : Tuple.Type_<Tail, readonly [T]> : readonly [] : readonly []
Computes the decoded tuple type for a tuple element schema array.
Details
Each element contributes its decoded Type; optional element schemas produce
optional tuple positions.
Type<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "Encoded": Tuple.type Tuple<Elements extends Tuple.Elements>.Encoded<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Encoded: infer T;
} ? Head extends {
readonly "~encoded.optionality": "optional";
} ? Tuple.Encoded_<Tail, readonly [(T | undefined)?]> : Tuple.Encoded_<Tail, readonly [T]> : readonly [] : readonly []
Computes the encoded tuple type for a tuple element schema array.
Details
Each element contributes its Encoded type; encoded-side optional element
schemas produce optional tuple positions.
Encoded<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "DecodingServices": Tuple.type Tuple<Elements extends Tuple.Elements>.DecodingServices<E extends Tuple.Elements> = E[number]["DecodingServices"]Union of all decoding service requirements needed by the tuple element
schemas.
DecodingServices<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "EncodingServices": Tuple.type Tuple<Elements extends Tuple.Elements>.EncodingServices<E extends Tuple.Elements> = E[number]["EncodingServices"]Union of all encoding service requirements needed by the tuple element
schemas.
EncodingServices<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "~type.make.in": Tuple.type Tuple<Elements extends Tuple.Elements>.MakeIn<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? Tuple.MakeIn_<Tail, readonly [(T | undefined)?]> : Tuple.MakeIn_<Tail, readonly [T]> : readonly [] : readonly []
Computes the input tuple type accepted when constructing a tuple value.
Details
Each element uses its ~type.make input type. Optional elements and elements
with constructor defaults produce optional tuple positions.
MakeIn<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "~type.make": Tuple.type Tuple<Elements extends Tuple.Elements>.MakeIn<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
"~type.make": infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} | {
readonly "~type.constructor.default": "with-default";
} ? Tuple.MakeIn_<Tail, readonly [(T | undefined)?]> : Tuple.MakeIn_<Tail, readonly [T]> : readonly [] : readonly []
Computes the input tuple type accepted when constructing a tuple value.
Details
Each element uses its ~type.make input type. Optional elements and elements
with constructor defaults produce optional tuple positions.
MakeIn<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly "Iso": Tuple.type Tuple<Elements extends Tuple.Elements>.Iso<E extends Tuple.Elements> = E extends readonly [infer Head, ...infer Tail] ? Head extends {
readonly Iso: infer T;
} ? Head extends {
readonly "~type.optionality": "optional";
} ? Tuple.Iso_<Tail, readonly [(T | undefined)?]> : Tuple.Iso_<Tail, readonly [T]> : readonly [] : readonly []
Computes the iso tuple type for a tuple element schema array from each
element schema's Iso type.
Iso<function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements>
readonly Tuple<Elements extends Tuple.Elements>.elements: Elements extends Tuple.Elementselements: function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements
/**
* Returns a new tuple with the elements modified by the provided function.
*
* **Details**
*
* Options:
*
* - `unsafePreserveChecks` - if `true`, keep any `.check(...)` constraints
* that were attached to the original union. Defaults to `false`.
*
* **Warning**: This is an unsafe operation. Since `mapFields`
* transformations change the schema type, the original refinement functions
* may no longer be valid or safe to apply to the transformed schema. Only
* use this option if you have verified that your refinements remain correct
* after the transformation.
*/
Tuple<To extends Tuple.Elements>(f: (elements: Elements) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Tuple<Simplify<Readonly<To>>>Returns a new tuple with the elements modified by the provided function.
Details
Options:
-
unsafePreserveChecks - if true, keep any .check(...) constraints
that were attached to the original union. Defaults to false.
Warning: This is an unsafe operation. Since mapFields
transformations change the schema type, the original refinement functions
may no longer be valid or safe to apply to the transformed schema. Only
use this option if you have verified that your refinements remain correct
after the transformation.
mapElements<function (type parameter) To in Tuple<Elements extends Tuple.Elements>.mapElements<To extends Tuple.Elements>(f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To extends Tuple.type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements>(
f: (elements: Elements) => Tof: (elements: Elements extends Tuple.Elementselements: function (type parameter) Elements in Tuple<Elements extends Tuple.Elements>Elements) => function (type parameter) To in Tuple<Elements extends Tuple.Elements>.mapElements<To extends Tuple.Elements>(f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To,
options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?: {
readonly unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks?: boolean | undefined
} | undefined
): interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<function (type parameter) To in Tuple<Elements extends Tuple.Elements>.mapElements<To extends Tuple.Elements>(f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To>>>
}
function function makeTuple<
Elements extends Tuple.Elements
>(
ast: SchemaAST.Arrays,
elements: Elements
): Tuple<Elements>
makeTuple<function (type parameter) Elements in makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements>Elements extends Tuple.type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements>(ast: SchemaAST.Arrays(parameter) ast: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast: import SchemaASTSchemaAST.class Arraysclass Arrays {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays, elements: Elements extends Tuple.Elementselements: function (type parameter) Elements in makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements>Elements): interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<function (type parameter) Elements in makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements>Elements> {
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(ast: SchemaAST.Arrays(parameter) ast: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, {
elements: Elements extends Tuple.Elementselements,
mapElements<To extends Tuple.Elements>(this: Tuple<Elements>, f: (elements: Elements) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Tuple<Simplify<Readonly<To>>>mapElements<function (type parameter) To in mapElements<To extends Tuple.Elements>(this: Tuple<Elements>, f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To extends Tuple.type Tuple<Elements extends Tuple.Elements>.Elements = readonly Constraint[]Constraint for the readonly array of element schemas used to define a
fixed-length Tuple schema.
Elements>(
this: Tuple<Elements>(parameter) this: {
Type: Tuple.Type<Elements>;
Encoded: Tuple.Encoded<Elements>;
DecodingServices: Tuple.DecodingServices<Elements>;
EncodingServices: Tuple.EncodingServices<Elements>;
Iso: Tuple.Iso<Elements>;
elements: Elements;
mapElements: (f: (elements: Elements) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Tuple<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Tuple.Type_<Elements, readonly []>, readonly []>) => Tuple<Elements>;
annotateKey: (annotations: Annotations.Key<Tuple.Type_<Elements, readonly []>>) => Tuple<Elements>;
check: (checks_0: SchemaAST.Check<Tuple.Type_<Elements, readonly []>>, ...checks: Array<SchemaAST.Check<Tuple.Type_<Elements, readonly []>>>) => Tuple<Elements>;
rebuild: (ast: SchemaAST.Arrays) => Tuple<Elements>;
make: (input: Tuple.MakeIn_<Elements, readonly []>, options?: MakeOptions) => Tuple.Type_<Elements, readonly []>;
makeOption: (input: Tuple.MakeIn_<Elements, readonly []>, options?: MakeOptions) => Option_.Option<Tuple.Type_<Elements, readonly []>>;
makeEffect: (input: Tuple.MakeIn_<Elements, readonly []>, options?: MakeOptions) => Effect.Effect<Tuple.Type_<Elements, readonly []>, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
this: interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<function (type parameter) Elements in makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements>Elements>,
f: (elements: Elements) => Tof: (elements: Elements extends Tuple.Elementselements: function (type parameter) Elements in makeTuple<Elements extends Tuple.Elements>(ast: SchemaAST.Arrays, elements: Elements): Tuple<Elements>Elements) => function (type parameter) To in mapElements<To extends Tuple.Elements>(this: Tuple<Elements>, f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To,
options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?: {
readonly unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks?: boolean | undefined
} | undefined
): interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<type Simplify<T> = { [K in keyof T]: T[K]; }Flattens intersection types into a single object type for readability.
When to use
Use when hovering over a type shows A & B & C instead of the merged shape.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It preserves readonly modifiers; use
Mutable
to strip them.
Example (Flattening an intersection)
import type { Struct } from "effect"
type Original = { a: string } & { b: number }
// Without Simplify, the type displays as `{ a: string } & { b: number }`
type Simplified = Struct.Simplify<Original>
// { a: string; b: number }
Simplify<type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<function (type parameter) To in mapElements<To extends Tuple.Elements>(this: Tuple<Elements>, f: (elements: Elements) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Tuple<Simplify<Readonly<To>>>
To>>> {
const const elements: To extends Tuple.Elementselements = f: (elements: Elements) => Tof(this.Tuple<Elements>.elements: Elements extends Tuple.Elementselements)
return function makeTuple<
Elements extends Tuple.Elements
>(
ast: SchemaAST.Arrays,
elements: Elements
): Tuple<Elements>
makeTuple(import SchemaASTSchemaAST.function tuple<
Elements extends Schema.Tuple.Elements
>(
elements: Elements,
checks?: Checks | undefined
): Arrays
tuple(const elements: To extends Tuple.Elementselements, options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?.unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks ? this.Bottom<unknown, unknown, unknown, unknown, Arrays, Tuple<Elements>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: SchemaAST.Arrays(property) Bottom<unknown, unknown, unknown, unknown, Arrays, Tuple<Elements>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Base.checks: Checks | undefinedchecks : var undefinedundefined), const elements: To extends Tuple.Elementselements)
}
})
}
/**
* Defines a fixed-length tuple schema from an array of element schemas.
*
* **Example** (Defining a pair of string and number)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.Tuple([Schema.String, Schema.Number])
*
* const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
* console.log(pair)
* // [ 'hello', 42 ]
* ```
*
* @category constructors
* @since 3.10.0
*/
export function function Tuple<
Elements extends ReadonlyArray<Constraint>
>(elements: Elements): Tuple<Elements>
Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Tuple<const function (type parameter) Elements in Tuple<const Elements extends ReadonlyArray<Constraint>>(elements: Elements): Tuple<Elements>Elements extends interface ReadonlyArray<T>ReadonlyArray<Constraint>>(elements: const Elements extends ReadonlyArray<Constraint>elements: function (type parameter) Elements in Tuple<const Elements extends ReadonlyArray<Constraint>>(elements: Elements): Tuple<Elements>Elements): interface Tuple<Elements extends Tuple.Elements>Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Namespace for Tuple type utilities.
Details
Tuple.Elements — constraint for the element schema array
Tuple.Type<E> — decoded tuple type
Tuple.Encoded<E> — encoded tuple type
Tuple.MakeIn<E> — constructor input tuple
Type-level representation returned by
Tuple
.
Tuple<function (type parameter) Elements in Tuple<const Elements extends ReadonlyArray<Constraint>>(elements: Elements): Tuple<Elements>Elements> {
return function makeTuple<
Elements extends Tuple.Elements
>(
ast: SchemaAST.Arrays,
elements: Elements
): Tuple<Elements>
makeTuple(import SchemaASTSchemaAST.function tuple<
Elements extends Schema.Tuple.Elements
>(
elements: Elements,
checks?: Checks | undefined
): Arrays
tuple(elements: const Elements extends ReadonlyArray<Constraint>elements), elements: const Elements extends ReadonlyArray<Constraint>elements)
}