mutable<S>Type-level representation returned by mutable.
export interface interface mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>Type-level representation returned by
mutable
.
Makes an array or tuple schema mutable, removing the readonly modifier.
Example (Defining mutable arrays)
import { Schema } from "effect"
const schema = Schema.mutable(Schema.Array(Schema.Number))
// number[] (mutable)
type T = typeof schema.Type
mutable<function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S extends Constraint & { readonly "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 }> 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<
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["ast"],
interface mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>Type-level representation returned by
mutable
.
Makes an array or tuple schema mutable, removing the readonly modifier.
Example (Defining mutable arrays)
import { Schema } from "effect"
const schema = Schema.mutable(Schema.Array(Schema.Number))
// number[] (mutable)
type T = typeof schema.Type
mutable<function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S>,
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.parameters"],
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.mutability"],
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.optionality"],
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.constructor.default"],
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~encoded.mutability"],
function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~encoded.optionality"]
>
{
readonly "Type": type Mutable<T> = { -readonly [K in keyof T]: T[K]; }Removes readonly modifiers from all properties of an object type.
When to use
Use when you need a mutable version of a readonly interface.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It also flattens intersections like
Simplify
.
Example (Making a readonly type mutable)
import type { Struct } from "effect"
type ReadOnly = { readonly a: string; readonly b: number }
type Writable = Struct.Mutable<ReadOnly>
// { a: string; b: number }
Mutable<function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["Type"]>
readonly "Encoded": type Mutable<T> = { -readonly [K in keyof T]: T[K]; }Removes readonly modifiers from all properties of an object type.
When to use
Use when you need a mutable version of a readonly interface.
Details
This helper is purely cosmetic at the type level and has no runtime effect.
It also flattens intersections like
Simplify
.
Example (Making a readonly type mutable)
import type { Struct } from "effect"
type ReadOnly = { readonly a: string; readonly b: number }
type Writable = Struct.Mutable<ReadOnly>
// { a: string; b: number }
Mutable<function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["Encoded"]>
readonly "DecodingServices": function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["DecodingServices"]
readonly "EncodingServices": function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["EncodingServices"]
// "~type.make" and "~type.make.in" as they are because they are contravariant
readonly "~type.make.in": function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.make.in"]
readonly "~type.make": function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["~type.make"]
readonly "Iso": function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S["Iso"]
readonly mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>.schema: S extends Constraint & { readonly "ast": SchemaAST.Arrays; }schema: function (type parameter) S in mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>S
}
interface mutableLambda extends Lambda {
<function (type parameter) S in <S extends Constraint & {
readonly "ast": SchemaAST.Arrays;
}>(self: S): mutable<S>
S extends Constraint & { readonly "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 }>(self: S extends Constraint & { readonly "ast": SchemaAST.Arrays; }self: function (type parameter) S in <S extends Constraint & {
readonly "ast": SchemaAST.Arrays;
}>(self: S): mutable<S>
S): interface mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>Type-level representation returned by
mutable
.
Makes an array or tuple schema mutable, removing the readonly modifier.
Example (Defining mutable arrays)
import { Schema } from "effect"
const schema = Schema.mutable(Schema.Array(Schema.Number))
// number[] (mutable)
type T = typeof schema.Type
mutable<function (type parameter) S in <S extends Constraint & {
readonly "ast": SchemaAST.Arrays;
}>(self: S): mutable<S>
S>
readonly "~lambda.out": this["~lambda.in"] extends Constraint & { readonly "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 } ?
interface mutable<S extends Constraint & { readonly "ast": SchemaAST.Arrays; }>Type-level representation returned by
mutable
.
Makes an array or tuple schema mutable, removing the readonly modifier.
Example (Defining mutable arrays)
import { Schema } from "effect"
const schema = Schema.mutable(Schema.Array(Schema.Number))
// number[] (mutable)
type T = typeof schema.Type
mutable<this["~lambda.in"]>
: "Error: schema not eligible for mutable"
}
/**
* Makes an array or tuple schema mutable, removing the `readonly` modifier.
*
* **Example** (Defining mutable arrays)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.mutable(Schema.Array(Schema.Number))
*
* // number[] (mutable)
* type T = typeof schema.Type
* ```
*
* @category transforming
* @since 3.10.0
*/
export const const mutable: mutableLambdaType-level representation returned by
mutable
.
Makes an array or tuple schema mutable, removing the readonly modifier.
Example (Defining mutable arrays)
import { Schema } from "effect"
const schema = Schema.mutable(Schema.Array(Schema.Number))
// number[] (mutable)
type T = typeof schema.Type
mutable = import Struct_Struct_.const lambda: <mutableLambda>(
f: (
a: Constraint & {
readonly ast: SchemaAST.Arrays
}
) => mutable<
Constraint & {
readonly ast: SchemaAST.Arrays
}
>
) => mutableLambda
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda<mutableLambda>((schema: Constraint & {
readonly ast: SchemaAST.Arrays
}
schema) => {
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(new import SchemaASTSchemaAST.constructor Arrays(isMutable: boolean, elements: ReadonlyArray<SchemaAST.AST>, rest: ReadonlyArray<SchemaAST.AST>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context, encodingChecks?: SchemaAST.Checks): SchemaAST.ArraysAST 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(true, schema: Constraint & {
readonly ast: SchemaAST.Arrays
}
schema."ast": SchemaAST.Arraysast.Arrays.elements: ReadonlyArray<AST>elements, schema: Constraint & {
readonly ast: SchemaAST.Arrays
}
schema."ast": SchemaAST.Arraysast.Arrays.rest: ReadonlyArray<AST>rest), { schema: Constraint & {
readonly ast: SchemaAST.Arrays
}
schema })
})