Class<Self, S, Inherited>Type-level representation returned by Class.
export interface interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self, function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S extends Constraint & { readonly fields: Struct.Fieldsfields: Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields }, function (type parameter) Inherited in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Inherited> 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 Declarationclass Declaration {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for user-defined opaque types with custom parsing logic.
When to use
Use when you need a custom schema AST node because none of the built-in
nodes fit.
Details
typeParameters — inner schemas this declaration is parameterized over
(e.g. the element type for a custom collection).
run — factory that receives typeParameters and returns a parser that
validates or transforms raw input.
Declaration,
interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self, function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["Encoded"], readonly [function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S], function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["Iso"]>, function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S>,
readonly [function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S],
function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.mutability"],
function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.optionality"],
function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.constructor.default"],
function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~encoded.mutability"],
function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~encoded.optionality"]
>
{
readonly "Type": function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self
readonly "Encoded": function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["Encoded"]
readonly "DecodingServices": function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["DecodingServices"]
readonly "EncodingServices": function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["EncodingServices"]
readonly "~type.make.in": type RequiredKeys<T> = { [K in keyof T]-?: {} extends Pick<T, K> ? never : K; }[keyof T]Extracts the required keys from a type.
When to use
Use to derive the keys whose properties must be present on an object type.
RequiredKeys<function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"]> extends never ? void | function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"]
: function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"]
readonly "~type.make": function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self
readonly "Iso": function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["Iso"]
new(
...args: {} extends S["~type.make.in"]
? [
props?: S["~type.make.in"],
options?: MakeOptions
]
: [
props: S["~type.make.in"],
options?: MakeOptions
]
args: {} extends function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"] ? [S["~type.make.in"] | undefinedprops?: function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"], MakeOptions | undefinedoptions?: MakeOptions]
: [S["~type.make.in"]props: function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["~type.make.in"], MakeOptions | undefinedoptions?: MakeOptions]
): function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["Type"] & function (type parameter) Inherited in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Inherited
readonly Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.identifier: stringidentifier: string
readonly Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.fields: S["fields"]fields: function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"]
/**
* Returns a new struct with the fields modified by the provided function.
*
* **Details**
*
* Options:
*
* - `unsafePreserveChecks` - if `true`, keep any `.check(...)` constraints
* that were attached to the original struct. 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.
*/
Class<To extends Struct.Fields>(f: (fields: S['fields']) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<Simplify<Readonly<To>>>Returns a new struct with the fields modified by the provided function.
Details
Options:
-
unsafePreserveChecks - if true, keep any .check(...) constraints
that were attached to the original struct. 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.
mapFields<function (type parameter) To in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To extends Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>(
f: (fields: S["fields"]) => Tof: (fields: S["fields"]fields: function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"]) => function (type parameter) To in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To,
options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?: {
readonly unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks?: boolean | undefined
} | undefined
): interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To>>>
/**
* Returns a function that creates a schema-backed subclass with this class's
* fields plus additional fields.
*
* **When to use**
*
* Use when you need a subclass whose constructor validates both inherited
* fields and newly added fields.
*
* **Details**
*
* The returned function accepts either a field map or a `Struct`. When you
* pass a `Struct`, checks attached to that extension schema are preserved and
* combined with checks from the base class schema.
*
* **Gotchas**
*
* Checks from a `Struct` argument are evaluated against the full subclass
* value after inherited and extension fields are merged. Object-wide checks
* such as `isMaxProperties` count inherited fields too.
*/
Class<Extended = never, Static = {}, Brand = {}>(identifier: string): { <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S['fields'], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<'Base.extend'> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S['fields'], NewFields>>>, Self & Brand>, Static>; <Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S['fields'], Extension['fields']>>>]>): [Extended] extends [never] ? MissingSelfGeneric<'Base.extend'> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S['fields'], Extension['fields']>>>, Self & Brand>, Static> }Returns a function that creates a schema-backed subclass with this class's
fields plus additional fields.
When to use
Use when you need a subclass whose constructor validates both inherited
fields and newly added fields.
Details
The returned function accepts either a field map or a Struct. When you
pass a Struct, checks attached to that extension schema are preserved and
combined with checks from the base class schema.
Gotchas
Checks from a Struct argument are evaluated against the full subclass
value after inherited and extension fields are merged. Object-wide checks
such as isMaxProperties count inherited fields too.
extend<function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended = never, function (type parameter) Static in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Static = {}, function (type parameter) Brand in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Brand = {}>(
identifier: stringidentifier: string
): {
<function (type parameter) NewFields in <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>NewFields extends Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>(
fields: NewFields extends Struct.Fieldsfields: function (type parameter) NewFields in <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>NewFields,
annotations: Annotations.Declaration<
Extended,
readonly [
Struct<
Simplify<Assign<S["fields"], NewFields>>
>
]
>
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended, readonly [interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 Assign<T, U> = { [K in keyof (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)]: (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)[K]; }Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }
Assign<function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"], function (type parameter) NewFields in <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>NewFields>>>]>
): [function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended] extends [never] ? type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<"Base.extend"> : type InheritStaticMembers<C, Static> = C &
Pick<Static, Exclude<keyof Static, keyof C>>
InheritStaticMembers<
interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended, interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 Assign<T, U> = { [K in keyof (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)]: (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)[K]; }Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }
Assign<function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"], function (type parameter) NewFields in <NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>NewFields>>>, function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self & function (type parameter) Brand in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Brand>,
function (type parameter) Static in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Static
>
<function (type parameter) Extension in <Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>Extension extends interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>>(
schema: Extension extends Struct<Struct.Fields>schema: function (type parameter) Extension in <Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>Extension,
annotations: Annotations.Declaration<
Extended,
readonly [
Struct<
Simplify<
Assign<S["fields"], Extension["fields"]>
>
>
]
>
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<
function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended,
readonly [interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 Assign<T, U> = { [K in keyof (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)]: (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)[K]; }Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }
Assign<function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"], function (type parameter) Extension in <Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>Extension["fields"]>>>]
>
): [function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended] extends [never] ? type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<"Base.extend"> : type InheritStaticMembers<C, Static> = C &
Pick<Static, Exclude<keyof Static, keyof C>>
InheritStaticMembers<
interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Extended in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Extended, interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 Assign<T, U> = { [K in keyof (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)]: (keyof T & keyof U extends never ? T & U : Omit<T, keyof T & keyof U> & U)[K]; }Merges two object types with properties from U taking precedence over T
on overlapping keys (like Object.assign at the type level).
When to use
Use when you need the type-level equivalent of { ...T, ...U }.
Details
When no keys overlap, this returns a simple intersection for efficiency.
When keys overlap, the type from U wins.
Example (Merging two types with overlapping keys)
import type { Struct } from "effect"
type A = { a: string; b: number }
type B = { b: boolean; c: string }
type Merged = Struct.Assign<A, B>
// { a: string; b: boolean; c: string }
Assign<function (type parameter) S in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>S["fields"], function (type parameter) Extension in <Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>Extension["fields"]>>>, function (type parameter) Self in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Self & function (type parameter) Brand in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Brand>,
function (type parameter) Static in Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>.extend<Extended = never, Static = {}, Brand = {}>(identifier: string): {
<NewFields extends Struct.Fields>(fields: NewFields, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], NewFields>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], NewFields>>>, Self & Brand>, Static>;
<Extension extends Struct<Struct.Fields>>(schema: Extension, annotations?: Annotations.Declaration<Extended, readonly [Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>]>): [Extended] extends [never] ? MissingSelfGeneric<"Base.extend"> : InheritStaticMembers<Class<Extended, Struct<Simplify<Assign<S["fields"], Extension["fields"]>>>, Self & Brand>, Static>;
}
Static
>
}
}
// Merges custom static members from a parent class onto the extended class,
// giving priority to the extended class's own members (e.g. schema-generated statics).
type type InheritStaticMembers<C, Static> = C &
Pick<Static, Exclude<keyof Static, keyof C>>
InheritStaticMembers<function (type parameter) C in type InheritStaticMembers<C, Static>C, function (type parameter) Static in type InheritStaticMembers<C, Static>Static> = function (type parameter) C in type InheritStaticMembers<C, Static>C & type Pick<T, K extends keyof T> = {
[P in K]: T[P]
}
From T, pick a set of properties whose keys are in the union K
Pick<function (type parameter) Static in type InheritStaticMembers<C, Static>Static, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<keyof function (type parameter) Static in type InheritStaticMembers<C, Static>Static, keyof function (type parameter) C in type InheritStaticMembers<C, Static>C>>
const const immerable: typeof immerableimmerable: unique symbol = module globalThisglobalThis.var Symbol: SymbolConstructorSymbol.SymbolConstructor.for(key: string): symbolReturns a Symbol object from the global symbol registry matching the given key if found.
Otherwise, returns a new symbol with this key.
for("immer-draftable") as any
const const payloadToken: {}payloadToken = {}
function function makeClass<
Self,
S extends Struct<Struct.Fields>,
Inherited extends new (
...args: ReadonlyArray<any>
) => any
>(
Inherited: Inherited,
identifier: string,
struct: S,
annotations:
| Annotations.Declaration<Self, readonly [S]>
| undefined,
proto:
| ((identifier: string) => object)
| undefined
): any
makeClass<
function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf,
function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS extends interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>,
function (type parameter) Inherited in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyInherited extends new(...args: readonly any[]args: interface ReadonlyArray<T>ReadonlyArray<any>) => any
>(
var Inherited: Inherited extends new (...args: ReadonlyArray<any>) => anyInherited: function (type parameter) Inherited in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyInherited,
identifier: stringidentifier: string,
struct: S extends Struct<Struct.Fields>struct: function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS,
annotations: | Annotations.Declaration<Self, readonly [S]>
| undefined
annotations: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf, readonly [function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS]> | undefined,
proto: | ((identifier: string) => object)
| undefined
proto: ((identifier: stringidentifier: string) => object) | undefined
): any {
const const getClassSchema: <
Self extends (new (
...args: ReadonlyArray<any>
) => any) & {
readonly identifier: string
}
>(
self: Self
) => decodeTo<
declareConstructor<
Self,
S["Encoded"],
readonly [S],
Self
>,
S,
never,
never
>
getClassSchema = function getClassSchemaFactory<
S extends Constraint
>(
from: S,
identifier: string,
annotations:
| Annotations.Declaration<any, readonly [S]>
| undefined
): <
Self extends (new (
...args: ReadonlyArray<any>
) => any) & { readonly identifier: string }
>(
self: Self
) => decodeTo<
declareConstructor<
Self,
S["Encoded"],
readonly [S]
>,
S
>
getClassSchemaFactory(struct: S extends Struct<Struct.Fields>struct, identifier: stringidentifier, annotations: | Annotations.Declaration<Self, readonly [S]>
| undefined
annotations)
const const ClassTypeId: stringClassTypeId = function getClassTypeId(
identifier: string
): string
getClassTypeId(identifier: stringidentifier) // HMR support
const const out: { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass.out; readonly identifier: string; readonly fields: Struct.Fields; get ast(): SchemaAST.Declaration;; pipe(): unknown; rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; make(input: S['~type.make.in'], options?: MakeOptions): Self; makeOption(input: S['~type.make.in'], options?: MakeOptions): Option_.Option<Self>; makeEffect(input: S['~type.make.in'], options?: MakeOptions): Effect.Effect<Self, SchemaError>; annotate(annotations: Annotations.Declaration<Self, readonly [S]>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; annotateKey(annotations: Annotations.Key<Self>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; check(checks_0: SchemaAST.Check<Self>, ...checks: Array<SchemaAST.Check<Self>>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; extend(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<any, readonly [any]>) => any; mapFields<To extends Struct.Fields>(f: (fields: S['fields']) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<Simplify<Readonly<To>>>; readonly "~effect/Schema/Schema": '~effect/Schema/Schema'; readonly [immerable]: true } & Inheritedout = class extends var Inherited: Inherited extends new (...args: ReadonlyArray<any>) => anyInherited {
constructor(...[input: anyinput, options: anyoptions]: interface ReadonlyArray<T>ReadonlyArray<any>) {
const const internalOptions:
| MakeOptions
| undefined
internalOptions = options: anyoptions as MakeOptions | undefined
const const payload:
| {
readonly token: unknown
readonly value: unknown
}
| undefined
payload = const internalOptions:
| MakeOptions
| undefined
internalOptions?.["~payload"]
const const value: unknownvalue = const payload:
| {
readonly token: unknown
readonly value: unknown
}
| undefined
payload?.token: unknowntoken === const payloadToken: {}payloadToken
? const payload: {
readonly token: unknown
readonly value: unknown
}
payload.value: unknownvalue
: struct: S extends Struct<Struct.Fields>struct.function Bottom(input: S['~type.make.in'], options?: MakeOptions): S['Type']Constructs a value from the make input representation synchronously.
When to use
Use when constructor input is trusted or when validation failure
should abort with a thrown Error.
Details
Applies constructor defaults and type-side validation according to
MakeOptions.
Gotchas
Throws an Error with the schema issue in its cause when validation
fails.
Causes that contain defects, interruptions, or other non-schema reasons
throw with the underlying Cause attached instead.
make(input: anyinput ?? {}, options: anyoptions)
super(const value: unknownvalue, { ...options: anyoptions, disableChecks: booleandisableChecks: true, "~payload": { token: {}token: const payloadToken: {}payloadToken, value: unknownvalue } })
}
static readonly [const TypeId: "~effect/Schema/Schema"TypeId] = const TypeId: "~effect/Schema/Schema"TypeId
get [const ClassTypeId: stringClassTypeId]() {
return const ClassTypeId: stringClassTypeId
}
static readonly [const immerable: typeof immerableimmerable] = true
static readonly out.identifier: stringidentifier = identifier: stringidentifier
static readonly out.fields: Struct.Fieldsfields = struct: S extends Struct<Struct.Fields>struct.Struct<Struct.Fields>.fields: Struct.FieldsThe field definitions of this struct. Spread them into a new struct to
reuse fields across schemas.
Example (Reusing fields across structs)
import { Schema } from "effect"
const Timestamped = Schema.Struct({
createdAt: Schema.Date,
updatedAt: Schema.Date
})
const User = Schema.Struct({
...Timestamped.fields,
name: Schema.String,
email: Schema.String
})
fields
static get out.ast: SchemaAST.Declaration(getter) out.ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast(): import SchemaASTSchemaAST.class Declarationclass Declaration {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for user-defined opaque types with custom parsing logic.
When to use
Use when you need a custom schema AST node because none of the built-in
nodes fit.
Details
typeParameters — inner schemas this declaration is parameterized over
(e.g. the element type for a custom collection).
run — factory that receives typeParameters and returns a parser that
validates or transforms raw input.
Declaration {
return const getClassSchema: <{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited>(self: {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited) => decodeTo<...>
getClassSchema(this).Bottom<unknown, unknown, unknown, unknown, Declaration, decodeTo<declareConstructor<{ new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited, S["Encoded"], readonly [...], { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited>, S, never, never>, ... 8 more ..., S["~encoded.optionality"]>["ast"]: SchemaAST.Declaration(property) Bottom<unknown, unknown, unknown, unknown, Declaration, decodeTo<declareConstructor<{ new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited, S["Encoded"], readonly [...], { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited>, S, never, never>, ... 8 more ..., S["~encoded.optionality"]>["ast"]: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast
}
static out.pipe(): anypipe() {
return import PipeablePipeable.pipeArguments(this, function (local var) arguments: IArgumentsarguments)
}
static out.rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
rebuild(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast: import SchemaASTSchemaAST.class Declarationclass Declaration {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for user-defined opaque types with custom parsing logic.
When to use
Use when you need a custom schema AST node because none of the built-in
nodes fit.
Details
typeParameters — inner schemas this declaration is parameterized over
(e.g. the element type for a custom collection).
run — factory that receives typeParameters and returns a parser that
validates or transforms raw input.
Declaration) {
return const getClassSchema: <{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited>(self: {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited) => decodeTo<...>
getClassSchema(this).Bottom<unknown, unknown, unknown, unknown, Declaration, decodeTo<declareConstructor<{ new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited, S["Encoded"], readonly [...], { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass<any, any, any>.out; readonly identifier: string; ... 13 more ...; readonly [immerable]: true; } & Inherited>, S, never, never>, ... 8 more ..., S["~encoded.optionality"]>.rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
rebuild(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast)
}
static out.make(input: S['~type.make.in'], options?: MakeOptions): Selfmake(input: S["~type.make.in"]input: function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS["~type.make.in"], options: MakeOptionsoptions?: MakeOptions): function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf {
return new this(input: S["~type.make.in"]input, options: MakeOptionsoptions)
}
static out.makeOption(input: S['~type.make.in'], options?: MakeOptions): Option_.Option<Self>makeOption(input: S["~type.make.in"]input: function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS["~type.make.in"], options: MakeOptionsoptions?: MakeOptions): import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf> {
return import SchemaParserSchemaParser.function makeOption<
S extends Schema.Constraint
>(
schema: S
): (
input: S["~type.make.in"],
options?: Schema.MakeOptions
) => Option.Option<S["Type"]>
Creates a synchronous maker that returns Option.some with the constructed
value on success, or Option.none when construction fails with schema issues.
When to use
Use when you need to validate schema constructor input and only care whether
construction succeeds, without exposing SchemaIssue.Issue details.
Gotchas
Only causes made entirely of schema issues are converted to Option.none.
Causes that contain defects, interruptions, or asynchronous work at this
synchronous boundary throw an Error whose cause is the underlying Cause.
makeOption(const getClassSchema: <{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited>(self: {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited) => decodeTo<...>
getClassSchema(this) as any)(input: S["~type.make.in"]input ?? {}, options: MakeOptionsoptions) as any
}
static out.makeEffect(input: S['~type.make.in'], options?: MakeOptions): Effect.Effect<Self, SchemaError>makeEffect(input: S["~type.make.in"]input: function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS["~type.make.in"], options: MakeOptionsoptions?: MakeOptions): import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf, class SchemaErrorclass SchemaError {
message: string;
toString: () => string;
name: string;
stack: string;
cause: unknown;
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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: SchemaIssue.Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError> {
return (const getClassSchema: <{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited>(self: {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
makeOption(input: S["~type.make.in"], options?: MakeOptions): Option_.Option<Self>;
... 7 more ...;
readonly [immerable]: true;
} & Inherited) => decodeTo<...>
getClassSchema(this) as any).makeEffect(input: S["~type.make.in"]input ?? {}, options: MakeOptionsoptions)
}
static out.annotate(annotations: Annotations.Declaration<Self, readonly [S]>): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
annotate(annotations: Annotations.Declaration<
Self,
readonly [S]
>
(parameter) annotations: {
toCodec: ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link) | undefined;
toCodecJson: ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link) | undefined;
toCodecIso: ((typeParameters: TypeParameters.Type<TypeParameters>) => SchemaAST.Link) | undefined;
toArbitrary: ToArbitrary.Declaration<T, TypeParameters> | undefined;
toEquivalence: ToEquivalence.Declaration<T, TypeParameters> | undefined;
toFormatter: ToFormatter.Declaration<T, TypeParameters> | undefined;
typeConstructor: { readonly _tag: string; readonly [key: string]: unknown } | undefined;
generation: { readonly runtime: string; readonly Type: string; readonly Encoded?: string | undefined; readonly importDeclaration?: string | undefined } | undefined;
message: string | undefined;
messageUnexpectedKey: string | undefined;
identifier: string | undefined;
parseOptions: SchemaAST.ParseOptions | undefined;
meta: Meta | undefined;
brands: ReadonlyArray<string> | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf, readonly [function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS]>) {
return this.out.rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
rebuild(import SchemaASTSchemaAST.function annotate<A extends AST>(
ast: A,
annotations: Schema.Annotations.Annotations
): A
annotate(this.out.ast: SchemaAST.Declaration(property) out.ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, annotations: Annotations.Declaration<
Self,
readonly [S]
>
(parameter) annotations: {
toCodec: ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link) | undefined;
toCodecJson: ((typeParameters: TypeParameters.Encoded<TypeParameters>) => SchemaAST.Link) | undefined;
toCodecIso: ((typeParameters: TypeParameters.Type<TypeParameters>) => SchemaAST.Link) | undefined;
toArbitrary: ToArbitrary.Declaration<T, TypeParameters> | undefined;
toEquivalence: ToEquivalence.Declaration<T, TypeParameters> | undefined;
toFormatter: ToFormatter.Declaration<T, TypeParameters> | undefined;
typeConstructor: { readonly _tag: string; readonly [key: string]: unknown } | undefined;
generation: { readonly runtime: string; readonly Type: string; readonly Encoded?: string | undefined; readonly importDeclaration?: string | undefined } | undefined;
message: string | undefined;
messageUnexpectedKey: string | undefined;
identifier: string | undefined;
parseOptions: SchemaAST.ParseOptions | undefined;
meta: Meta | undefined;
brands: ReadonlyArray<string> | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations))
}
static out.annotateKey(annotations: Annotations.Key<Self>): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
annotateKey(annotations: Annotations.Key<Self>(parameter) annotations: {
messageMissingKey: string | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations: Annotations.interface Annotations.Key<T>Annotations for struct property schemas. Extends
Documentation
with an optional messageMissingKey to override the error message when
the property key is absent during decoding.
Key<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf>) {
return this.out.rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
rebuild(import SchemaASTSchemaAST.function annotateKey<A extends AST>(
ast: A,
annotations: Schema.Annotations.Key<unknown>
): A
annotateKey(this.out.ast: SchemaAST.Declaration(property) out.ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, annotations: Annotations.Key<Self>(parameter) annotations: {
messageMissingKey: string | undefined;
default: T | undefined;
examples: ReadonlyArray<T> | undefined;
expected: string | undefined;
title: string | undefined;
description: string | undefined;
documentation: string | undefined;
readOnly: boolean | undefined;
writeOnly: boolean | undefined;
format: string | undefined;
contentEncoding: string | undefined;
contentMediaType: string | undefined;
}
annotations))
}
static out.check(checks_0: SchemaAST.Check<Self>, ...checks: SchemaAST.Check<Self>[]): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
... 9 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
... 9 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
check(...checks: readonly [
SchemaAST.Check<Self>,
...Array<SchemaAST.Check<Self>>
]
(parameter) checks: {
0: SchemaAST.Check<Self>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<SchemaAST.Check<Self>>>): Array<SchemaAST.Check<Self>>; (...items: Array<SchemaAST.Check<Self> | ConcatArray<SchemaAST.Check<Self>>>): Array<SchemaAST.Check<Self>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<SchemaAST.Check<Self>>;
indexOf: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => number;
every: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<Sc…;
some: (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Chec…;
reduce: { (callbackfn: (previousValue: SchemaAST.Check<Self>, currentValue: SchemaAST.Check<Self>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => SchemaAST.Check<Self>): SchemaAST.Check<Self>; (callbackfn: (previousValue: Sc…;
reduceRight: { (callbackfn: (previousValue: SchemaAST.Check<Self>, currentValue: SchemaAST.Check<Self>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => SchemaAST.Check<Self>): SchemaAST.Check<Self>; (callbackfn: (previousValue: Sc…;
find: { (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Che…;
findIndex: (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, SchemaAST.Check<Self>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaAST.Check<Self>>;
includes: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaAST.Check<Self>, index: number, array: Array<SchemaAST.Check<Self>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaAST.Check<Self> | undefined;
findLast: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST…;
findLastIndex: (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaAST.Check<Self>>;
toSorted: (compareFn?: ((a: SchemaAST.Check<Self>, b: SchemaAST.Check<Self>) => number) | undefined) => Array<SchemaAST.Check<Self>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<Self>>): Array<SchemaAST.Check<Self>>; (start: number, deleteCount?: number): Array<SchemaAST.Check<Self>> };
with: (index: number, value: SchemaAST.Check<Self>) => Array<SchemaAST.Check<Self>>;
}
checks: readonly [import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf>, ...interface Array<T>Array<import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<function (type parameter) Self in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anySelf>>]) {
return this.out.rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<{
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited, S["Encoded"], readonly [...], {
new (...[input, options]: ReadonlyArray<any>): out;
prototype: makeClass<any, any, any>.out;
readonly identifier: string;
readonly fields: Struct<Fields extends Struct.Fields>.Fields;
get ast(): SchemaAST.Declaration;
pipe(): any;
rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<... & Inherited, S["Encoded"], readonly [S], ... & Inherited>, S, never, never>;
make(input: S["~type.make.in"], options?: MakeOptions): Self;
... 8 more ...;
readonly [immerable]: true;
} & Inherited>, S, never, never>
rebuild(import SchemaASTSchemaAST.function appendChecks<A extends AST>(
ast: A,
checks: Checks | undefined
): A
appendChecks(this.out.ast: SchemaAST.Declaration(property) out.ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, checks: readonly [
SchemaAST.Check<Self>,
...Array<SchemaAST.Check<Self>>
]
(parameter) checks: {
0: SchemaAST.Check<Self>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<SchemaAST.Check<Self>>>): Array<SchemaAST.Check<Self>>; (...items: Array<SchemaAST.Check<Self> | ConcatArray<SchemaAST.Check<Self>>>): Array<SchemaAST.Check<Self>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<SchemaAST.Check<Self>>;
indexOf: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => number;
every: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<Sc…;
some: (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Chec…;
reduce: { (callbackfn: (previousValue: SchemaAST.Check<Self>, currentValue: SchemaAST.Check<Self>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => SchemaAST.Check<Self>): SchemaAST.Check<Self>; (callbackfn: (previousValue: Sc…;
reduceRight: { (callbackfn: (previousValue: SchemaAST.Check<Self>, currentValue: SchemaAST.Check<Self>, currentIndex: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => SchemaAST.Check<Self>): SchemaAST.Check<Self>; (callbackfn: (previousValue: Sc…;
find: { (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Che…;
findIndex: (predicate: (value: SchemaAST.Check<Self>, index: number, obj: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, SchemaAST.Check<Self>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaAST.Check<Self>>;
includes: (searchElement: SchemaAST.Check<Self>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaAST.Check<Self>, index: number, array: Array<SchemaAST.Check<Self>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaAST.Check<Self> | undefined;
findLast: { (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST…;
findLastIndex: (predicate: (value: SchemaAST.Check<Self>, index: number, array: ReadonlyArray<SchemaAST.Check<Self>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaAST.Check<Self>>;
toSorted: (compareFn?: ((a: SchemaAST.Check<Self>, b: SchemaAST.Check<Self>) => number) | undefined) => Array<SchemaAST.Check<Self>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<Self>>): Array<SchemaAST.Check<Self>>; (start: number, deleteCount?: number): Array<SchemaAST.Check<Self>> };
with: (index: number, value: SchemaAST.Check<Self>) => Array<SchemaAST.Check<Self>>;
}
checks))
}
static out.extend(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<any, readonly [any]>) => anyextend(
identifier: stringidentifier: string
) {
return (
schema: Struct.Fields | Struct<Struct.Fields>schema: Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields | interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>,
annotations: | Annotations.Declaration<any, readonly [any]>
| undefined
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<any, readonly [any]>
) => {
const const extension: Struct<Struct.Fields>const extension: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
extension = function isStruct(
schema: Struct.Fields | Struct<Struct.Fields>
): schema is Struct<Struct.Fields>
isStruct(schema: Struct.Fields | Struct<Struct.Fields>schema) ? schema: Struct.Fields | Struct<Struct.Fields>(parameter) schema: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
schema : function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct(schema: Struct.Fields | Struct<Struct.Fields>schema)
const const fields: {
[x: string]: Constraint
[x: number]: Constraint
[x: symbol]: Constraint
}
fields = { ...struct: S extends Struct<Struct.Fields>struct.Struct<Struct.Fields>.fields: Struct.FieldsThe field definitions of this struct. Spread them into a new struct to
reuse fields across schemas.
Example (Reusing fields across structs)
import { Schema } from "effect"
const Timestamped = Schema.Struct({
createdAt: Schema.Date,
updatedAt: Schema.Date
})
const User = Schema.Struct({
...Timestamped.fields,
name: Schema.String,
email: Schema.String
})
fields, ...const extension: Struct<Struct.Fields>const extension: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
extension.Struct<Struct.Fields>.fields: Struct.FieldsThe field definitions of this struct. Spread them into a new struct to
reuse fields across schemas.
Example (Reusing fields across structs)
import { Schema } from "effect"
const Timestamped = Schema.Struct({
createdAt: Schema.Date,
updatedAt: Schema.Date
})
const User = Schema.Struct({
...Timestamped.fields,
name: Schema.String,
email: Schema.String
})
fields }
const const ast: SchemaAST.Objectsconst ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast = import SchemaASTSchemaAST.function struct<
Fields extends Schema.Struct.Fields
>(
fields: Fields,
checks: Checks | undefined,
annotations?: Schema.Annotations.Annotations
): Objects
struct(const fields: {
[x: string]: Constraint
[x: number]: Constraint
[x: symbol]: Constraint
}
fields, struct: S extends Struct<Struct.Fields>struct.Bottom<unknown, unknown, unknown, unknown, Objects, Struct<Struct<Fields extends Struct.Fields>.Fields>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: SchemaAST.Objects(property) Bottom<unknown, unknown, unknown, unknown, Objects, Struct<Struct<Fields extends Struct.Fields>.Fields>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Base.checks: Checks | undefinedchecks, { identifier: stringidentifier })
return function makeClass<
Self,
S extends Struct<Struct.Fields>,
Inherited extends new (
...args: ReadonlyArray<any>
) => any
>(
Inherited: Inherited,
identifier: string,
struct: S,
annotations:
| Annotations.Declaration<Self, readonly [S]>
| undefined,
proto:
| ((identifier: string) => object)
| undefined
): any
makeClass(
this,
identifier: stringidentifier,
function makeStruct<
Fields extends Struct.Fields
>(
ast: SchemaAST.Objects,
fields: Fields
): Struct<Fields>
makeStruct(import SchemaASTSchemaAST.function appendChecks<A extends AST>(
ast: A,
checks: Checks | undefined
): A
appendChecks(const ast: SchemaAST.Objectsconst ast: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, const extension: Struct<Struct.Fields>const extension: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
extension.Bottom<unknown, unknown, unknown, unknown, Objects, Struct<Struct<Fields extends Struct.Fields>.Fields>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: SchemaAST.Objects(property) Bottom<unknown, unknown, unknown, unknown, Objects, Struct<Struct<Fields extends Struct.Fields>.Fields>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast.Base.checks: Checks | undefinedchecks), const fields: {
[x: string]: Constraint
[x: number]: Constraint
[x: symbol]: Constraint
}
fields),
annotations: | Annotations.Declaration<any, readonly [any]>
| undefined
annotations,
proto: | ((identifier: string) => object)
| undefined
proto
)
}
}
static out.mapFields<To extends Struct.Fields>(f: (fields: S['fields']) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<Simplify<Readonly<To>>>mapFields<function (type parameter) To in out.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To extends Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>(
f: (fields: S["fields"]) => Tof: (fields: S["fields"]fields: function (type parameter) S in makeClass<Self, S extends Struct<Struct.Fields>, Inherited extends new (...args: ReadonlyArray<any>) => any>(Inherited: Inherited, identifier: string, struct: S, annotations: Annotations.Declaration<Self, readonly [S]> | undefined, proto: ((identifier: string) => object) | undefined): anyS["fields"]) => function (type parameter) To in out.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To,
options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?: {
readonly unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks?: boolean | undefined
} | undefined
): interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<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 out.mapFields<To extends Struct.Fields>(f: (fields: S["fields"]) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To>>> {
return struct: S extends Struct<Struct.Fields>struct.Struct<Struct.Fields>.mapFields<To>(f: (fields: Struct<Fields extends Struct.Fields>.Fields) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>
Returns a new struct with the fields 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.
mapFields(f: (fields: S["fields"]) => Tof, options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options)
}
}
if (proto: | ((identifier: string) => object)
| undefined
proto !== var undefinedundefined) {
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.assign<makeClass<any, any, any>.out, object>(target: makeClass<any, any, any>.out, source: object): makeClass<any, any, any>.out & object (+3 overloads)Copy the values of all of the enumerable own properties from one or more source objects to a
target object. Returns the target object.
assign(const out: { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass.out; readonly identifier: string; readonly fields: Struct.Fields; get ast(): SchemaAST.Declaration;; pipe(): unknown; rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; make(input: S['~type.make.in'], options?: MakeOptions): Self; makeOption(input: S['~type.make.in'], options?: MakeOptions): Option_.Option<Self>; makeEffect(input: S['~type.make.in'], options?: MakeOptions): Effect.Effect<Self, SchemaError>; annotate(annotations: Annotations.Declaration<Self, readonly [S]>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; annotateKey(annotations: Annotations.Key<Self>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; check(checks_0: SchemaAST.Check<Self>, ...checks: Array<SchemaAST.Check<Self>>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; extend(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<any, readonly [any]>) => any; mapFields<To extends Struct.Fields>(f: (fields: S['fields']) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<Simplify<Readonly<To>>>; readonly "~effect/Schema/Schema": '~effect/Schema/Schema'; readonly [immerable]: true } & Inheritedout.out.prototype: makeClass<any, any, any>.outprototype, proto: (identifier: string) => objectproto(identifier: stringidentifier))
}
return const out: { new (...[input, options]: ReadonlyArray<any>): out; prototype: makeClass.out; readonly identifier: string; readonly fields: Struct.Fields; get ast(): SchemaAST.Declaration;; pipe(): unknown; rebuild(ast: SchemaAST.Declaration): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; make(input: S['~type.make.in'], options?: MakeOptions): Self; makeOption(input: S['~type.make.in'], options?: MakeOptions): Option_.Option<Self>; makeEffect(input: S['~type.make.in'], options?: MakeOptions): Effect.Effect<Self, SchemaError>; annotate(annotations: Annotations.Declaration<Self, readonly [S]>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; annotateKey(annotations: Annotations.Key<Self>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; check(checks_0: SchemaAST.Check<Self>, ...checks: Array<SchemaAST.Check<Self>>): decodeTo<declareConstructor<any & Inherited, S['Encoded'], readonly [S], any & Inherited>, S, never, never>; extend(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<any, readonly [any]>) => any; mapFields<To extends Struct.Fields>(f: (fields: S['fields']) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<Simplify<Readonly<To>>>; readonly "~effect/Schema/Schema": '~effect/Schema/Schema'; readonly [immerable]: true } & Inheritedout
}
function function getClassTransformation(
self: new (...args: ReadonlyArray<any>) => any
): SchemaTransformation.Transformation<
any,
any,
never,
never
>
getClassTransformation(self: new (...args: ReadonlyArray<any>) => anyself: new(...args: readonly any[]args: interface ReadonlyArray<T>ReadonlyArray<any>) => any) {
return new import SchemaTransformationSchemaTransformation.constructor Transformation<any, any, never, never>(decode: SchemaGetter.Getter<any, any, never>, encode: SchemaGetter.Getter<any, any, never>): SchemaTransformation.Transformation<any, any, never, never>Represents a bidirectional transformation between a decoded type T and an encoded
type E, built from a pair of Getters.
When to use
Use when you need a schema transformation that defines how a schema converts
between two representations.
- You want to compose multiple transformations into a pipeline.
- You want to flip a transformation to swap decode/encode.
Details
This is the primary building block for Schema.decodeTo, Schema.encodeTo,
Schema.decode, Schema.encode, and Schema.link. Each direction is a
SchemaGetter.Getter that handles optionality, failure, and Effect services.
- Immutable —
flip() and compose() return new instances.
flip() swaps the decode and encode getters.
compose(other) chains: this.decode then other.decode for decoding,
other.encode then this.encode for encoding.
Example (Composing two transformations)
import { SchemaTransformation } from "effect"
const trimAndLower = SchemaTransformation.trim().compose(
SchemaTransformation.toLowerCase()
)
// decode: trim then lowercase
// encode: passthrough (both directions)
Transformation<any, any, never, never>(
import SchemaGetterSchemaGetter.function transform<T, E>(
f: (e: E) => T
): Getter<T, E>
Creates a getter that applies a pure function to present values.
When to use
Use when you need a schema getter for a pure, infallible transformation
between types.
- Building encode/decode pairs for
Schema.decodeTo.
Details
- This is the most commonly used constructor.
- Transforms
Some(e) to Some(f(e)) and leaves None unchanged.
- Skips
None inputs — only called when a value is present.
- Never fails.
Example (Transforming strings to numbers)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(Schema.Number, {
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
})
)
transform((input: anyinput) => new self: new (...args: ReadonlyArray<any>) => anyself(input: anyinput)),
import SchemaGetterSchemaGetter.function passthrough<any>(): SchemaGetter.Getter<any, any, never> (+1 overload)Returns the identity getter — passes the value through unchanged.
When to use
Use when you need a schema getter for one side of a decodeTo pair, either
encode or decode, to pass values through unchanged.
Details
- Pure, no allocation (singleton instance).
- Optimized away during
.compose() — composing with a passthrough is free.
- The default overload requires
T === E. Pass { strict: false } to opt
out of the type constraint.
Example (Passing through identity transformations)
import { Schema, SchemaGetter } from "effect"
// No transformation needed — types already match
const StringToString = Schema.String.pipe(
Schema.decodeTo(Schema.String, {
decode: SchemaGetter.passthrough(),
encode: SchemaGetter.passthrough()
})
)
passthrough()
)
}
function function getClassTypeId(
identifier: string
): string
getClassTypeId(identifier: stringidentifier: string) {
return `~effect/Schema/Class/${identifier: stringidentifier}`
}
function function getClassSchemaFactory<
S extends Constraint
>(
from: S,
identifier: string,
annotations:
| Annotations.Declaration<any, readonly [S]>
| undefined
): <
Self extends (new (
...args: ReadonlyArray<any>
) => any) & { readonly identifier: string }
>(
self: Self
) => decodeTo<
declareConstructor<
Self,
S["Encoded"],
readonly [S]
>,
S
>
getClassSchemaFactory<function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S extends Constraint>(
from: S extends Constraintfrom: function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S,
identifier: stringidentifier: string,
annotations: | Annotations.Declaration<any, readonly [S]>
| undefined
annotations: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<any, readonly [function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S]> | undefined
) {
let let memo:
| decodeTo<
declareConstructor<
any,
S["Encoded"],
readonly [S]
>,
S
>
| undefined
memo: interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<any, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"], readonly [function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S]>, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S> | undefined
return <function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self extends (new(...args: readonly any[]args: interface ReadonlyArray<T>ReadonlyArray<any>) => any) & { readonly identifier: stringidentifier: string }>(
self: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }self: function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self
): interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"], readonly [function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S]>, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S> => {
if (let memo:
| decodeTo<
declareConstructor<
any,
S["Encoded"],
readonly [S]
>,
S
>
| undefined
memo !== var undefinedundefined) {
return let memo:
| decodeTo<
declareConstructor<
any,
S["Encoded"],
readonly [S]
>,
S
>
| undefined
let memo: {
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<any, readonly [S]>) => decodeTo<declareConstructor<any, S['Encoded'], readonly [S], any>, S, never, never>;
annotateKey: (annotations: Annotations.Key<any>) => decodeTo<declareConstructor<any, S['Encoded'], readonly [S], any>, S, never, never>;
check: (checks_0: SchemaAST.Check<any>, ...checks: Array<SchemaAST.Check<any>>) => decodeTo<declareConstructor<any, S['Encoded'], readonly [S], any>, S, never, never>;
rebuild: (ast: SchemaAST.Declaration) => decodeTo<declareConstructor<any, S['Encoded'], readonly [S], any>, S, never, never>;
make: (input: any, options?: MakeOptions) => any;
makeOption: (input: any, options?: MakeOptions) => Option_.Option<any>;
makeEffect: (input: any, options?: MakeOptions) => Effect.Effect<any, 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; <…;
}
memo
}
const const transformation: SchemaTransformation.Transformation<
any,
any,
never,
never
>
const transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, RD2, RE2>;
}
transformation = function getClassTransformation(
self: new (...args: ReadonlyArray<any>) => any
): SchemaTransformation.Transformation<
any,
any,
never,
never
>
getClassTransformation(self: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }self)
const const to: declareConstructor<
Self,
S["Encoded"],
readonly [S],
Self
>
const to: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Self, readonly [S]>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
annotateKey: (annotations: Annotations.Key<Self>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
check: (checks_0: SchemaAST.Check<Self>, ...checks: Array<SchemaAST.Check<Self>>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
make: (input: Self, options?: MakeOptions) => Self;
makeOption: (input: Self, options?: MakeOptions) => Option_.Option<Self>;
makeEffect: (input: Self, options?: MakeOptions) => Effect.Effect<Self, 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; <…;
}
to = 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<interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"], readonly [function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S]>>(
new import SchemaASTSchemaAST.constructor Declaration(typeParameters: ReadonlyArray<SchemaAST.AST>, run: (typeParameters: ReadonlyArray<SchemaAST.AST>) => (input: unknown, self: SchemaAST.Declaration, options: SchemaAST.ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context, encodingChecks?: SchemaAST.Checks): SchemaAST.DeclarationAST node for user-defined opaque types with custom parsing logic.
When to use
Use when you need a custom schema AST node because none of the built-in
nodes fit.
Details
typeParameters — inner schemas this declaration is parameterized over
(e.g. the element type for a custom collection).
run — factory that receives typeParameters and returns a parser that
validates or transforms raw input.
Declaration(
[from: S extends Constraintfrom.Constraint["ast"]: SchemaAST.ASTast],
() => (input: unknowninput, ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast) => {
return input: unknowninput instanceof self: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }self ||
import PredicatePredicate.hasProperty(input: unknowninput, function getClassTypeId(
identifier: string
): string
getClassTypeId(identifier: stringidentifier)) ?
import EffectEffect.succeed(input: unknowninput) :
import EffectEffect.fail(new import SchemaIssueSchemaIssue.constructor InvalidType(ast: SchemaAST.AST, actual: StandardJSONSchemaV1<unknown>): SchemaIssue.InvalidTypeRepresents a schema issue produced when the runtime type of the input does not match the type
expected by the schema (e.g. got null when string was expected).
When to use
Use when you need to detect basic type mismatches, such as a wrong primitive
or null where an object was expected.
Details
ast is the schema node that expected a different type.
actual is Option.some(value) when the input was present, or
Option.none() when no value was provided.
- The default formatter renders this as
"Expected <type>, got <actual>".
Example (Formatting output)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.String)(42)
} catch (e) {
if (Schema.isSchemaError(e)) {
console.log(String(e.issue))
// "Expected string, got 42"
}
}
InvalidType(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, import Option_Option_.some(input: unknowninput)))
},
{
identifier: stringidentifier,
[import SchemaASTSchemaAST.const ClassTypeId: "~effect/Schema/Class"ClassTypeId]: ([from: SchemaAST.ASTfrom]: readonly [import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST]) => new import SchemaASTSchemaAST.constructor Link(to: SchemaAST.AST, transformation: SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any>): SchemaAST.LinkRepresents a single step in an
Encoding
chain.
Details
A link pairs a target
AST
with a Transformation or Middleware
that converts values between the current node and the target.
to — the AST node on the other side of this transformation step.
transformation — the bidirectional conversion logic (decode/encode).
Links are composed into a non-empty array (
Encoding
) attached to
AST nodes that have a different encoded representation.
Link(from: SchemaAST.ASTfrom, const transformation: SchemaTransformation.Transformation<
any,
any,
never,
never
>
const transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, RD2, RE2>;
}
transformation),
toCodec: ([from]: readonly [
ConstraintCodec<S["Encoded"], S["Encoded"]>
]) => SchemaAST.Link
toCodec: ([from: ConstraintCodec<
S["Encoded"],
S["Encoded"],
never,
never
>
(parameter) from: {
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
ast: SchemaAST.AST;
Iso: unknown;
}
from]: readonly [interface ConstraintCodec<out T, out E = T, out RD = never, out RE = never>Lightweight structural constraint for APIs that need codec type views but do
not need the full schema protocol.
When to use
Use when you need to preserve decoded type, encoded type, and service
requirements for a schema value, but the API does not call schema methods
such as annotate, check, rebuild, make, or makeEffect.
ConstraintCodec<function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"], function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"]>]) =>
new import SchemaASTSchemaAST.constructor Link(to: SchemaAST.AST, transformation: SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any>): SchemaAST.LinkRepresents a single step in an
Encoding
chain.
Details
A link pairs a target
AST
with a Transformation or Middleware
that converts values between the current node and the target.
to — the AST node on the other side of this transformation step.
transformation — the bidirectional conversion logic (decode/encode).
Links are composed into a non-empty array (
Encoding
) attached to
AST nodes that have a different encoded representation.
Link(from: ConstraintCodec<
S["Encoded"],
S["Encoded"],
never,
never
>
(parameter) from: {
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
ast: SchemaAST.AST;
Iso: unknown;
}
from.Constraint["ast"]: SchemaAST.ASTast, const transformation: SchemaTransformation.Transformation<
any,
any,
never,
never
>
const transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, RD2, RE2>;
}
transformation),
toArbitrary: ([from]: readonly [
Annotations.ToArbitrary.TypeParameter<S["Type"]>
]) => () => {
arbitrary: any
terminal: any
}
toArbitrary: ([from: Annotations.ToArbitrary.TypeParameter<
S["Type"]
>
(parameter) from: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
from]: readonly [Annotations.namespace Annotations.ToArbitraryTypes used by arbitrary-derivation annotations to configure toArbitrary
hooks, filter hints, candidate sources, diagnostics, and merged generation
constraints.
ToArbitrary.interface Annotations.ToArbitrary.TypeParameter<T>Arbitrary generators derived for a declaration type parameter.
Details
arbitrary is the normal generator. terminal is the finite generator
used while building recursive terminal branches and is undefined when
no finite path is known. Optional containers can ignore it; non-empty
containers need it for their terminal branch.
TypeParameter<function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Type"]>]) => () => ({
arbitrary: anyarbitrary: from: Annotations.ToArbitrary.TypeParameter<
S["Type"]
>
(parameter) from: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
from.Annotations.ToArbitrary.TypeParameter<T>.arbitrary: FastCheck.Arbitrary<T>arbitrary.map((args: S["Type"]args: function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Type"]) => new self: Self
new (...args: ReadonlyArray<any>) => any
self(args: S["Type"]args)),
terminal: anyterminal: from: Annotations.ToArbitrary.TypeParameter<
S["Type"]
>
(parameter) from: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
from.Annotations.ToArbitrary.TypeParameter<T>.terminal: anyterminal?.map((args: S["Type"]args: function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Type"]) => new self: Self
new (...args: ReadonlyArray<any>) => any
self(args: S["Type"]args))
}),
toFormatter: ([from]: readonly [
Formatter<S["Type"]>
]) => (t: Self) => string
toFormatter: ([from: Formatter<S["Type"], string>from]: readonly [import FormatterFormatter<function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Type"]>]) => (t: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }t: function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self) => `${self: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }self.identifier: stringidentifier}(${from: Formatter<S["Type"], string>from(t: Self extends (new (...args: ReadonlyArray<any>) => any) & { readonly identifier: string; }t)})`,
"~sentinels": import SchemaASTSchemaAST.function collectSentinels(
ast: AST
): Array<Sentinel>
collectSentinels(from: S extends Constraintfrom.Constraint["ast"]: SchemaAST.ASTast),
...annotations: | Annotations.Declaration<any, readonly [S]>
| undefined
annotations
}
)
)
return let memo:
| decodeTo<
declareConstructor<
any,
S["Encoded"],
readonly [S]
>,
S
>
| undefined
memo = function decodeTo<declareConstructor<Self, S["Encoded"], readonly [S], Self>, S, never, never>(to: declareConstructor<Self, S["Encoded"], readonly [S], Self>, transformation: {
readonly decode: SchemaGetter.Getter<NoInfer<S["Encoded"]>, NoInfer<S["Type"]>, never>;
readonly encode: SchemaGetter.Getter<NoInfer<S["Type"]>, NoInfer<S["Encoded"]>, never>;
}): (from: S) => decodeTo<...> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo<interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<function (type parameter) Self in <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self): decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
Self, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S["Encoded"], readonly [function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S]>, function (type parameter) S in getClassSchemaFactory<S extends Constraint>(from: S, identifier: string, annotations: Annotations.Declaration<any, readonly [S]> | undefined): <Self extends (new (...args: ReadonlyArray<any>) => any) & {
readonly identifier: string;
}>(self: Self) => decodeTo<declareConstructor<Self, S["Encoded"], readonly [S]>, S>
S>(const to: declareConstructor<
Self,
S["Encoded"],
readonly [S],
Self
>
const to: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Self, readonly [S]>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
annotateKey: (annotations: Annotations.Key<Self>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
check: (checks_0: SchemaAST.Check<Self>, ...checks: Array<SchemaAST.Check<Self>>) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Self, S['Encoded'], readonly [S], Self>;
make: (input: Self, options?: MakeOptions) => Self;
makeOption: (input: Self, options?: MakeOptions) => Option_.Option<Self>;
makeEffect: (input: Self, options?: MakeOptions) => Effect.Effect<Self, 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; <…;
}
to, const transformation: SchemaTransformation.Transformation<
any,
any,
never,
never
>
const transformation: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<any, any, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, any, RD2, RE2>) => SchemaTransformation.Transformation<T2, any, RD2, RE2>;
}
transformation)(from: S extends Constraintfrom)
}
}
function function isStruct(
schema: Struct.Fields | Struct<Struct.Fields>
): schema is Struct<Struct.Fields>
isStruct(schema: Struct.Fields | Struct<Struct.Fields>schema: Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields | interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>): schema: Struct.Fields | Struct<Struct.Fields>schema is interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields> {
return function isSchema(u: unknown): u is TopChecks whether a value is a Schema.
isSchema(schema: Struct.Fields | Struct<Struct.Fields>schema)
}
type type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<function (type parameter) Usage in type MissingSelfGeneric<Usage extends string>Usage extends string> =
`Missing \`Self\` generic - use \`class Self extends ${function (type parameter) Usage in type MissingSelfGeneric<Usage extends string>Usage}<Self>(...)\``
/**
* Creates a schema-backed class whose constructor validates input against a
* {@link Struct} schema. Construction throws a {@link SchemaError} on invalid
* input.
*
* **When to use**
*
* Use when you need a schema-backed data class with validated construction,
* schema-derived decoding/encoding, and class-style methods or inheritance.
*
* **Details**
*
* Pass the desired class type as the first type parameter. The second optional
* type parameter can be used to add nominal brands.
*
* **Gotchas**
*
* Passing `disableChecks` in the options skips constructor validation.
*
* **Example** (Defining a basic class)
*
* ```ts
* import { Schema } from "effect"
*
* class Person extends Schema.Class<Person>("Person")({
* name: Schema.String,
* age: Schema.Number
* }) {}
*
* const alice = new Person({ name: "Alice", age: 30 })
* console.log(alice.name) // "Alice"
* console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
* ```
*
* **Example** (Extending a class)
*
* ```ts
* import { Schema } from "effect"
*
* class Animal extends Schema.Class<Animal>("Animal")({
* name: Schema.String
* }) {}
*
* class Dog extends Animal.extend<Dog>("Dog")({
* breed: Schema.String
* }) {}
*
* const dog = new Dog({ name: "Rex", breed: "Labrador" })
* console.log(dog.name) // "Rex"
* console.log(dog.breed) // "Labrador"
* ```
*
* @see {@link TaggedClass} for adding a `_tag` literal field to the class schema
* @see {@link ErrorClass} for defining schema-backed error classes
* @see {@link TaggedErrorClass} for defining tagged schema-backed error classes
*
* @category constructors
* @since 3.10.0
*/
export const const Class: {
<Self = never, Brand = {}>(
identifier: string
): {
<Fields extends Struct.Fields>(
fields: Fields,
annotations?: Annotations.Declaration<
Self,
readonly [Struct<Fields>]
>
): [Self] extends [never]
? MissingSelfGeneric<"Schema.Class">
: Class<Self, Struct<Fields>, Brand>
<S extends Struct<Struct.Fields>>(
schema: S,
annotations?: Annotations.Declaration<
Self,
readonly [S]
>
): [Self] extends [never]
? MissingSelfGeneric<"Schema.Class">
: Class<Self, S, Brand>
}
}
Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class: {
<function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self = never, function (type parameter) Brand in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Brand = {}>(identifier: stringidentifier: string): {
<const function (type parameter) Fields in <const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>Fields extends Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>(
fields: const Fields extends Struct.Fieldsfields: function (type parameter) Fields in <const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>Fields,
annotations: Annotations.Declaration<
Self,
readonly [Struct<Fields>]
>
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self, readonly [interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<function (type parameter) Fields in <const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>Fields>]>
): [function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self] extends [never] ? type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<"Schema.Class"> : interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self, interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<function (type parameter) Fields in <const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>Fields>, function (type parameter) Brand in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Brand>
<function (type parameter) S in <S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>S extends interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>>(
schema: S extends Struct<Struct.Fields>schema: function (type parameter) S in <S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>S,
annotations: | Annotations.Declaration<Self, readonly [S]>
| undefined
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self, readonly [function (type parameter) S in <S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>S]>
): [function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self] extends [never] ? type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<"Schema.Class"> : interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Self in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Self, function (type parameter) S in <S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>S, function (type parameter) Brand in <Self = never, Brand = {}>(identifier: string): {
<const Fields extends Struct.Fields>(fields: Fields, annotations?: Annotations.Declaration<Self, readonly [Struct<Fields>]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Fields>, Brand>;
<S extends Struct<Struct.Fields>>(schema: S, annotations?: Annotations.Declaration<Self, readonly [S]>): [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, S, Brand>;
}
Brand>
}
} = <function (type parameter) Self in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Self, function (type parameter) Brand in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Brand = {}>(identifier: stringidentifier: string) =>
(
schema: Struct.Fields | Struct<Struct.Fields>schema: Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields | interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>,
annotations: Annotations.Declaration<
Self,
readonly [Struct<Struct.Fields>]
>
annotations?: Annotations.interface Annotations.Declaration<T, TypeParameters extends ReadonlyArray<Constraint> = readonly []>Full annotation set for Declaration schema nodes — used when defining
custom, opaque schema types via Schema.declare. Extends
Bottom
with optional codec, arbitrary, equivalence, and formatter hooks so that
derived capabilities (JSON encoding, property testing, etc.) can be
provided for the custom type.
Declaration<function (type parameter) Self in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Self, readonly [interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>]>
): [function (type parameter) Self in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Self] extends [never] ? type MissingSelfGeneric<
Usage extends string
> =
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>(...)\``
MissingSelfGeneric<"Schema.Class"> : interface Class<Self, S extends Constraint & { readonly fields: Struct.Fields; }, Inherited>Type-level representation returned by
Class
.
Creates a schema-backed class whose constructor validates input against a
Struct
schema. Construction throws a
SchemaError
on invalid
input.
When to use
Use when you need a schema-backed data class with validated construction,
schema-derived decoding/encoding, and class-style methods or inheritance.
Details
Pass the desired class type as the first type parameter. The second optional
type parameter can be used to add nominal brands.
Gotchas
Passing disableChecks in the options skips constructor validation.
Example (Defining a basic class)
import { Schema } from "effect"
class Person extends Schema.Class<Person>("Person")({
name: Schema.String,
age: Schema.Number
}) {}
const alice = new Person({ name: "Alice", age: 30 })
console.log(alice.name) // "Alice"
console.log(`${alice}`) // "Person({ name: Alice, age: 30 })"
Example (Extending a class)
import { Schema } from "effect"
class Animal extends Schema.Class<Animal>("Animal")({
name: Schema.String
}) {}
class Dog extends Animal.extend<Dog>("Dog")({
breed: Schema.String
}) {}
const dog = new Dog({ name: "Rex", breed: "Labrador" })
console.log(dog.name) // "Rex"
console.log(dog.breed) // "Labrador"
Class<function (type parameter) Self in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Self, interface Struct<Fields extends Struct.Fields>Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Namespace for struct field type utilities.
Details
These types compute the decoded Type, encoded Encoded, and constructor
input MakeIn of a
Struct
from its field map, handling optional,
mutable, and other field modifiers automatically.
Struct.Fields — constraint for the field map object
Struct.Type<F> — decoded type of the struct
Struct.Encoded<F> — encoded type of the struct
Struct.MakeIn<F> — constructor input (optional/defaulted fields may be omitted)
Struct.DecodingServices<F> / Struct.EncodingServices<F> — required services
Type-level representation returned by
Struct
.
Struct<Struct.type Struct<Fields extends Struct.Fields>.Fields = {
readonly [x: string]: Constraint;
readonly [x: number]: Constraint;
readonly [x: symbol]: Constraint;
}
Constraint for a struct field map: an object whose values are schemas.
Fields>, function (type parameter) Brand in <Self, Brand = {}>(identifier: string): (schema: Struct.Fields | Struct<Struct.Fields>, annotations?: Annotations.Declaration<Self, readonly [Struct<Struct.Fields>]>) => [Self] extends [never] ? MissingSelfGeneric<"Schema.Class"> : Class<Self, Struct<Struct.Fields>, Brand>Brand> => {
const const struct: Struct<Struct.Fields>const struct: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
struct = function isStruct(
schema: Struct.Fields | Struct<Struct.Fields>
): schema is Struct<Struct.Fields>
isStruct(schema: Struct.Fields | Struct<Struct.Fields>schema) ? schema: Struct.Fields | Struct<Struct.Fields>(parameter) schema: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
schema : function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct(schema: Struct.Fields | Struct<Struct.Fields>schema)
return function makeClass<
Self,
S extends Struct<Struct.Fields>,
Inherited extends new (
...args: ReadonlyArray<any>
) => any
>(
Inherited: Inherited,
identifier: string,
struct: S,
annotations:
| Annotations.Declaration<Self, readonly [S]>
| undefined,
proto:
| ((identifier: string) => object)
| undefined
): any
makeClass(
import DataData.Class,
identifier: stringidentifier,
const struct: Struct<Struct.Fields>const struct: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: Struct.Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<Struct.ReadonlySide<Struct.Fields, 'Type'>, readonly []>) => Struct<Struct.Fields>;
annotateKey: (annotations: Annotations.Key<Struct.ReadonlySide<Struct.Fields, 'Type'>>) => Struct<Struct.Fields>;
check: (checks_0: SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>, ...checks: Array<SchemaAST.Check<Struct.ReadonlySide<Struct.Fields, 'Type'>>>) => Struct<Struct.Fields>;
rebuild: (ast: SchemaAST.Objects) => Struct<Struct.Fields>;
make: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Struct.ReadonlySide<Struct.Fields, 'Type'>;
makeOption: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<Struct.Fields, 'Type'>>;
makeEffect: (input: Struct.ReadonlyMakeIn<Struct.Fields>, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<Struct.Fields, 'Type'>, 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; <…;
}
struct,
annotations: Annotations.Declaration<
Self,
readonly [Struct<Struct.Fields>]
>
annotations,
(identifier: stringidentifier) => ({
Object.toString(): stringReturns a string representation of an object.
toString() {
return `${identifier: stringidentifier}(${import formatformat({ ...this })})`
}
})
)
}