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 }export declare namespace Struct {
/**
* Constraint for a struct field map: an object whose values are schemas.
*
* @category utility types
* @since 3.10.0
*/
export type 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 = { readonly [x: PropertyKeyx: type PropertyKey =
| string
| number
| symbol
PropertyKey]: Constraint }
type type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.optionality": "optional";
} ? K : never; }[keyof Fields]
TypeOptionalKeys<function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields>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> = {
[function (type parameter) KK in keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields>Fields]: function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields>Fields[function (type parameter) KK] extends { readonly "~type.optionality": "optional" } ? function (type parameter) KK
: never
}[keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields>Fields]
type type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.mutability": "mutable";
} ? K : never; }[keyof Fields]
TypeMutableKeys<function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields>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> = {
[function (type parameter) KK in keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields>Fields]: function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields>Fields[function (type parameter) KK] extends { readonly "~type.mutability": "mutable" } ? function (type parameter) KK
: never
}[keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields>Fields]
type type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>SetOptional<function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>K extends keyof function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>A> = type Omit<T, K extends keyof any> = {
[P in Exclude<keyof T, K>]: T[P]
}
Construct a type with the properties of T except for those in type K.
Omit<function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>K> & type Partial<T> = {
[P in keyof T]?: T[P] | undefined
}
Make all properties in T optional
Partial<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) A in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A>K>>
type type Struct<Fields extends Struct.Fields>.Mutable<A> = { -readonly [K in keyof A]: A[K]; }Mutable<function (type parameter) A in type Struct<Fields extends Struct.Fields>.Mutable<A>A> = { -readonly [function (type parameter) KK in keyof function (type parameter) A in type Struct<Fields extends Struct.Fields>.Mutable<A>A]: function (type parameter) A in type Struct<Fields extends Struct.Fields>.Mutable<A>A[function (type parameter) KK] }
type type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A> = Omit<A, K> & Mutable<Pick<A, K>>SetMutable<function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>K extends keyof function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>A> = type Omit<T, K extends keyof any> = {
[P in Exclude<keyof T, K>]: T[P]
}
Construct a type with the properties of T except for those in type K.
Omit<function (type parameter) A in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>K> & type Struct<Fields extends Struct.Fields>.Mutable<A> = { -readonly [K in keyof A]: A[K]; }Mutable<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) A in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>A, function (type parameter) K in type Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A>K>>
type type Struct<Fields extends Struct.Fields>.Side = "Type" | "Encoded" | "Iso"Side = "Type" | "Iso" | "Encoded"
type type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~encoded.optionality": "optional";
} ? K : never; }[keyof Fields]
EncodedOptionalKeys<function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields>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> = {
[function (type parameter) KK in keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields>Fields]: function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields>Fields[function (type parameter) KK] extends { readonly "~encoded.optionality": "optional" } ? function (type parameter) KK
: never
}[keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields>Fields]
type type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~encoded.mutability": "mutable";
} ? K : never; }[keyof Fields]
EncodedMutableKeys<function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields>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> = {
[function (type parameter) KK in keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields>Fields]: function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields>Fields[function (type parameter) KK] extends { readonly "~encoded.mutability": "mutable" } ? function (type parameter) KK
: never
}[keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields>Fields]
type type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side> = S extends "Encoded" ? EncodedOptionalKeys<F> : TypeOptionalKeys<F>SideOptionalKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side>F extends 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) S in type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side>S extends type Struct<Fields extends Struct.Fields>.Side = "Type" | "Encoded" | "Iso"Side> = function (type parameter) S in type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side>S extends "Encoded" ? type Struct<Fields extends Struct.Fields>.EncodedOptionalKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~encoded.optionality": "optional";
} ? K : never; }[keyof Fields]
EncodedOptionalKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side>F>
: type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.optionality": "optional";
} ? K : never; }[keyof Fields]
TypeOptionalKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side>F>
type type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side> = S extends "Encoded" ? EncodedMutableKeys<F> : TypeMutableKeys<F>SideMutableKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side>F extends 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) S in type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side>S extends type Struct<Fields extends Struct.Fields>.Side = "Type" | "Encoded" | "Iso"Side> = function (type parameter) S in type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side>S extends "Encoded" ? type Struct<Fields extends Struct.Fields>.EncodedMutableKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~encoded.mutability": "mutable";
} ? K : never; }[keyof Fields]
EncodedMutableKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side>F>
: type Struct<Fields extends Struct.Fields>.TypeMutableKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.mutability": "mutable";
} ? K : never; }[keyof Fields]
TypeMutableKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side>F>
type type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side>F extends 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) S in type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side>S extends type Struct<Fields extends Struct.Fields>.Side = "Type" | "Encoded" | "Iso"Side> = { readonly [function (type parameter) KK in keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side>F]: function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side>F[function (type parameter) KK][function (type parameter) S in type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side>S] }
type type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>> = [O | M] extends [never] ? ReadonlySide<F, S> : [M] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, S>, O>]: SetOptional<ReadonlySide<F, S>, O>[K]; } : [O] extends [never] ? { [K in keyof SetMutable<ReadonlySide<F, S>, M>]: SetMutable<ReadonlySide<F, S>, M>[K]; } : { [K in keyof SetMutable<SetOptional<ReadonlySide<F, S>, O>, Extract<...> | Extract<...>>]: SetMutable<...>[K]; }View<
function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F extends 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) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S extends type Struct<Fields extends Struct.Fields>.Side = "Type" | "Encoded" | "Iso"Side,
function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O extends keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F = type Struct<Fields extends Struct.Fields>.SideOptionalKeys<F extends Struct.Fields, S extends Struct.Side> = S extends "Encoded" ? EncodedOptionalKeys<F> : TypeOptionalKeys<F>SideOptionalKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>,
function (type parameter) M in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>M extends keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F = type Struct<Fields extends Struct.Fields>.SideMutableKeys<F extends Struct.Fields, S extends Struct.Side> = S extends "Encoded" ? EncodedMutableKeys<F> : TypeMutableKeys<F>SideMutableKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>
> = [function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O | function (type parameter) M in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>M] extends [never] ? type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>
: [function (type parameter) M in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>M] extends [never] ? 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 Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>SetOptional<type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>, function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O>>
: [function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O] extends [never] ? 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 Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A> = Omit<A, K> & Mutable<Pick<A, K>>SetMutable<type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>, function (type parameter) M in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>M>>
: 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 Struct<Fields extends Struct.Fields>.SetMutable<A, K extends keyof A> = Omit<A, K> & Mutable<Pick<A, K>>SetMutable<
type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>SetOptional<type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>, function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O>,
type Extract<T, U> = T extends U
? T
: never
Extract from T those types that are assignable to U
Extract<keyof type Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>SetOptional<type Struct<Fields extends Struct.Fields>.ReadonlySide<F extends Struct.Fields, S extends Struct.Side> = { readonly [K in keyof F]: F[K][S]; }ReadonlySide<function (type parameter) F in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>F, function (type parameter) S in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>S>, function (type parameter) O in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>O>, function (type parameter) M in type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>>M>
>
>
/**
* Computes the decoded object type for a struct field map.
*
* **Details**
*
* Field schemas contribute their decoded `Type`. `optionalKey` and `optional`
* produce optional properties, while `mutableKey` produces writable properties.
*
* @category utility types
* @since 3.10.0
*/
export type type Struct<Fields extends Struct.Fields>.Type<F extends Struct.Fields> = [TypeOptionalKeys<F> | TypeMutableKeys<F>] extends [never] ? ReadonlySide<F, "Type"> : [TypeMutableKeys<F>] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, "Type">, TypeOptionalKeys<F>>]: SetOptional<ReadonlySide<F, "Type">, TypeOptionalKeys<F>>[K]; } : [TypeOptionalKeys<F>] extends [never] ? { [K in keyof SetMutable<...>]: SetMutable<...>[K]; } : { [K in keyof SetMutable<...>]: SetMutable<...>[K]; }Computes the decoded object type for a struct field map.
Details
Field schemas contribute their decoded Type. optionalKey and optional
produce optional properties, while mutableKey produces writable properties.
Type<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Type<F extends Struct.Fields>F extends 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> = type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>> = [O | M] extends [never] ? ReadonlySide<F, S> : [M] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, S>, O>]: SetOptional<ReadonlySide<F, S>, O>[K]; } : [O] extends [never] ? { [K in keyof SetMutable<ReadonlySide<F, S>, M>]: SetMutable<ReadonlySide<F, S>, M>[K]; } : { [K in keyof SetMutable<SetOptional<ReadonlySide<F, S>, O>, Extract<...> | Extract<...>>]: SetMutable<...>[K]; }View<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Type<F extends Struct.Fields>F, "Type">
/**
* Computes the iso object type for a struct field map from each field schema's
* `Iso` type.
*
* **Details**
*
* The resulting property optionality and mutability follow the same field
* modifiers used by `Struct.Type`.
*
* @category utility types
* @since 4.0.0
*/
export type type Struct<Fields extends Struct.Fields>.Iso<F extends Struct.Fields> = [TypeOptionalKeys<F> | TypeMutableKeys<F>] extends [never] ? ReadonlySide<F, "Iso"> : [TypeMutableKeys<F>] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, "Iso">, TypeOptionalKeys<F>>]: SetOptional<ReadonlySide<F, "Iso">, TypeOptionalKeys<F>>[K]; } : [TypeOptionalKeys<F>] extends [never] ? { [K in keyof SetMutable<...>]: SetMutable<...>[K]; } : { [K in keyof SetMutable<...>]: SetMutable<...>[K]; }Computes the iso object type for a struct field map from each field schema's
Iso type.
Details
The resulting property optionality and mutability follow the same field
modifiers used by Struct.Type.
Iso<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Iso<F extends Struct.Fields>F extends 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> = type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>> = [O | M] extends [never] ? ReadonlySide<F, S> : [M] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, S>, O>]: SetOptional<ReadonlySide<F, S>, O>[K]; } : [O] extends [never] ? { [K in keyof SetMutable<ReadonlySide<F, S>, M>]: SetMutable<ReadonlySide<F, S>, M>[K]; } : { [K in keyof SetMutable<SetOptional<ReadonlySide<F, S>, O>, Extract<...> | Extract<...>>]: SetMutable<...>[K]; }View<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Iso<F extends Struct.Fields>F, "Iso">
/**
* Computes the encoded object type for a struct field map.
*
* **Details**
*
* Field schemas contribute their `Encoded` type. Encoded-side optionality and
* mutability modifiers determine whether properties are optional or writable in
* the encoded shape.
*
* @category utility types
* @since 3.10.0
*/
export type type Struct<Fields extends Struct.Fields>.Encoded<F extends Struct.Fields> = [EncodedOptionalKeys<F> | EncodedMutableKeys<F>] extends [never] ? ReadonlySide<F, "Encoded"> : [EncodedMutableKeys<F>] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, "Encoded">, EncodedOptionalKeys<F>>]: SetOptional<ReadonlySide<F, "Encoded">, EncodedOptionalKeys<F>>[K]; } : [EncodedOptionalKeys<F>] extends [...] ? { [K in keyof SetMutable<...>]: SetMutable<...>[K]; } : { [K in keyof SetMutable<...>]: SetMutable<...>[K]; }Computes the encoded object type for a struct field map.
Details
Field schemas contribute their Encoded type. Encoded-side optionality and
mutability modifiers determine whether properties are optional or writable in
the encoded shape.
Encoded<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Encoded<F extends Struct.Fields>F extends 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> = type Struct<Fields extends Struct.Fields>.View<F extends Struct.Fields, S extends Struct.Side, O extends keyof F = Struct.SideOptionalKeys<F, S>, M extends keyof F = Struct.SideMutableKeys<F, S>> = [O | M] extends [never] ? ReadonlySide<F, S> : [M] extends [never] ? { [K in keyof SetOptional<ReadonlySide<F, S>, O>]: SetOptional<ReadonlySide<F, S>, O>[K]; } : [O] extends [never] ? { [K in keyof SetMutable<ReadonlySide<F, S>, M>]: SetMutable<ReadonlySide<F, S>, M>[K]; } : { [K in keyof SetMutable<SetOptional<ReadonlySide<F, S>, O>, Extract<...> | Extract<...>>]: SetMutable<...>[K]; }View<function (type parameter) F in type Struct<Fields extends Struct.Fields>.Encoded<F extends Struct.Fields>F, "Encoded">
/**
* Union of all decoding service requirements needed by the schemas in a struct
* field map.
*
* @category utility types
* @since 4.0.0
*/
export type type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["DecodingServices"]; }[keyof F]Union of all decoding service requirements needed by the schemas in a struct
field map.
DecodingServices<function (type parameter) F in type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields>F extends 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> = { readonly [function (type parameter) KK in keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields>F]: function (type parameter) F in type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields>F[function (type parameter) KK]["DecodingServices"] }[keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields>F]
/**
* Union of all encoding service requirements needed by the schemas in a struct
* field map.
*
* @category utility types
* @since 4.0.0
*/
export type type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["EncodingServices"]; }[keyof F]Union of all encoding service requirements needed by the schemas in a struct
field map.
EncodingServices<function (type parameter) F in type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields>F extends 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> = { readonly [function (type parameter) KK in keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields>F]: function (type parameter) F in type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields>F[function (type parameter) KK]["EncodingServices"] }[keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields>F]
type type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.constructor.default": "with-default";
} ? K : never; }[keyof Fields]
TypeConstructorDefaultedKeys<function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields>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> = {
[function (type parameter) KK in keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields>Fields]: function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields>Fields[function (type parameter) KK] extends { readonly "~type.constructor.default": "with-default" } ? function (type parameter) KK
: never
}[keyof function (type parameter) Fields in type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields>Fields]
type type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["~type.make"]; }ReadonlyMakeIn<function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields>F extends 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> = { readonly [function (type parameter) KK in keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields>F]: function (type parameter) F in type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields>F[function (type parameter) KK]["~type.make"] }
type type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>> = [O] extends [never] ? ReadonlyMakeIn<F> : { [K in keyof SetOptional<ReadonlyMakeIn<F>, O>]: SetOptional<ReadonlyMakeIn<F>, O>[K]; }MakeInView<
function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F extends 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) O in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>O extends keyof function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F = type Struct<Fields extends Struct.Fields>.TypeOptionalKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.optionality": "optional";
} ? K : never; }[keyof Fields]
TypeOptionalKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F> | type Struct<Fields extends Struct.Fields>.TypeConstructorDefaultedKeys<Fields extends Struct.Fields> = { [K in keyof Fields]: Fields[K] extends {
readonly "~type.constructor.default": "with-default";
} ? K : never; }[keyof Fields]
TypeConstructorDefaultedKeys<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F>
> = [function (type parameter) O in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>O] extends [never] ? type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["~type.make"]; }ReadonlyMakeIn<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F> : 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 Struct<Fields extends Struct.Fields>.SetOptional<A, K extends keyof A> = Omit<A, K> & Partial<Pick<A, K>>SetOptional<type Struct<Fields extends Struct.Fields>.ReadonlyMakeIn<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["~type.make"]; }ReadonlyMakeIn<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>F>, function (type parameter) O in type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>O>>
/**
* Computes the input object type accepted when constructing a struct value.
*
* **Details**
*
* Required fields use each field schema's `~type.make` input. Fields marked
* optional or with a constructor default may be omitted.
*
* @category utility types
* @since 4.0.0
*/
export type type Struct<Fields extends Struct.Fields>.MakeIn<F extends Struct.Fields> = [TypeOptionalKeys<F> | TypeConstructorDefaultedKeys<F>] extends [never] ? ReadonlyMakeIn<F> : { [K in keyof SetOptional<ReadonlyMakeIn<F>, TypeOptionalKeys<F> | TypeConstructorDefaultedKeys<F>>]: SetOptional<ReadonlyMakeIn<F>, TypeOptionalKeys<F> | TypeConstructorDefaultedKeys<F>>[K]; }Computes the input object type accepted when constructing a struct value.
Details
Required fields use each field schema's ~type.make input. Fields marked
optional or with a constructor default may be omitted.
MakeIn<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeIn<F extends Struct.Fields>F extends 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> = type Struct<Fields extends Struct.Fields>.MakeInView<F extends Struct.Fields, O extends keyof F = Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>> = [O] extends [never] ? ReadonlyMakeIn<F> : { [K in keyof SetOptional<ReadonlyMakeIn<F>, O>]: SetOptional<ReadonlyMakeIn<F>, O>[K]; }MakeInView<function (type parameter) F in type Struct<Fields extends Struct.Fields>.MakeIn<F extends Struct.Fields>F>
}
/**
* Type-level representation returned by {@link Struct}.
*
* @category models
* @since 3.10.0
*/
export interface 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 Struct<Fields extends Struct.Fields>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> 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 Objectsclass Objects {
_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 node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects, 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 Struct<Fields extends Struct.Fields>Fields>> {
readonly "Type": Struct.type Struct<Fields extends Struct.Fields>.Type<F extends Struct.Fields> = [Struct.TypeOptionalKeys<F> | Struct.TypeMutableKeys<F>] extends [never] ? Struct.ReadonlySide<F, "Type"> : [Struct.TypeMutableKeys<F>] extends [never] ? { [K in keyof Struct.SetOptional<Struct.ReadonlySide<F, "Type">, Struct.TypeOptionalKeys<F>>]: Struct.SetOptional<Struct.ReadonlySide<F, "Type">, Struct.TypeOptionalKeys<F>>[K]; } : [Struct.TypeOptionalKeys<F>] extends [never] ? { [K in keyof Struct.SetMutable<Struct.ReadonlySide<F, "Type">, Struct.TypeMutableKeys<...>>]: Struct.SetMutable<...>[K]; } : { [K in keyof Struct.SetMutable<...>]: Struct.SetMutable<...>[K]; }Computes the decoded object type for a struct field map.
Details
Field schemas contribute their decoded Type. optionalKey and optional
produce optional properties, while mutableKey produces writable properties.
Type<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "Encoded": Struct.type Struct<Fields extends Struct.Fields>.Encoded<F extends Struct.Fields> = [Struct.EncodedOptionalKeys<F> | Struct.EncodedMutableKeys<F>] extends [never] ? Struct.ReadonlySide<F, "Encoded"> : [Struct.EncodedMutableKeys<F>] extends [never] ? { [K in keyof Struct.SetOptional<Struct.ReadonlySide<F, "Encoded">, Struct.EncodedOptionalKeys<F>>]: Struct.SetOptional<Struct.ReadonlySide<F, "Encoded">, Struct.EncodedOptionalKeys<F>>[K]; } : [Struct.EncodedOptionalKeys<F>] extends [...] ? { [K in keyof Struct.SetMutable<...>]: Struct.SetMutable<...>[K]; } : { [K in keyof Struct.SetMutable<...>]: Struct.SetMutable<...>[K]; }Computes the encoded object type for a struct field map.
Details
Field schemas contribute their Encoded type. Encoded-side optionality and
mutability modifiers determine whether properties are optional or writable in
the encoded shape.
Encoded<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "DecodingServices": Struct.type Struct<Fields extends Struct.Fields>.DecodingServices<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["DecodingServices"]; }[keyof F]Union of all decoding service requirements needed by the schemas in a struct
field map.
DecodingServices<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "EncodingServices": Struct.type Struct<Fields extends Struct.Fields>.EncodingServices<F extends Struct.Fields> = { readonly [K in keyof F]: F[K]["EncodingServices"]; }[keyof F]Union of all encoding service requirements needed by the schemas in a struct
field map.
EncodingServices<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "~type.make.in": Struct.type Struct<Fields extends Struct.Fields>.MakeIn<F extends Struct.Fields> = [Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>] extends [never] ? Struct.ReadonlyMakeIn<F> : { [K in keyof Struct.SetOptional<Struct.ReadonlyMakeIn<F>, Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>]: Struct.SetOptional<Struct.ReadonlyMakeIn<F>, Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>[K]; }Computes the input object type accepted when constructing a struct value.
Details
Required fields use each field schema's ~type.make input. Fields marked
optional or with a constructor default may be omitted.
MakeIn<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "~type.make": Struct.type Struct<Fields extends Struct.Fields>.MakeIn<F extends Struct.Fields> = [Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>] extends [never] ? Struct.ReadonlyMakeIn<F> : { [K in keyof Struct.SetOptional<Struct.ReadonlyMakeIn<F>, Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>]: Struct.SetOptional<Struct.ReadonlyMakeIn<F>, Struct.TypeOptionalKeys<F> | Struct.TypeConstructorDefaultedKeys<F>>[K]; }Computes the input object type accepted when constructing a struct value.
Details
Required fields use each field schema's ~type.make input. Fields marked
optional or with a constructor default may be omitted.
MakeIn<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
readonly "Iso": Struct.type Struct<Fields extends Struct.Fields>.Iso<F extends Struct.Fields> = [Struct.TypeOptionalKeys<F> | Struct.TypeMutableKeys<F>] extends [never] ? Struct.ReadonlySide<F, "Iso"> : [Struct.TypeMutableKeys<F>] extends [never] ? { [K in keyof Struct.SetOptional<Struct.ReadonlySide<F, "Iso">, Struct.TypeOptionalKeys<F>>]: Struct.SetOptional<Struct.ReadonlySide<F, "Iso">, Struct.TypeOptionalKeys<F>>[K]; } : [Struct.TypeOptionalKeys<F>] extends [never] ? { [K in keyof Struct.SetMutable<Struct.ReadonlySide<F, "Iso">, Struct.TypeMutableKeys<...>>]: Struct.SetMutable<...>[K]; } : { [K in keyof Struct.SetMutable<...>]: Struct.SetMutable<...>[K]; }Computes the iso object type for a struct field map from each field schema's
Iso type.
Details
The resulting property optionality and mutability follow the same field
modifiers used by Struct.Type.
Iso<function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields>
/**
* The field definitions of this struct. Spread them into a new struct to
* reuse fields across schemas.
*
* **Example** (Reusing fields across structs)
*
* ```ts
* 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
* })
* ```
*/
readonly Struct<Fields extends Struct.Fields>.fields: Fields extends 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: function (type parameter) Fields in Struct<Fields extends Struct.Fields>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 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.
*/
Struct<To extends Struct.Fields>(f: (fields: 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 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<function (type parameter) To in Struct<Fields extends Struct.Fields>.mapFields<To extends Struct.Fields>(f: (fields: 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: Fields) => Tof: (fields: Fields extends Struct.Fieldsfields: function (type parameter) Fields in Struct<Fields extends Struct.Fields>Fields) => function (type parameter) To in Struct<Fields extends Struct.Fields>.mapFields<To extends Struct.Fields>(f: (fields: 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 Struct<Fields extends Struct.Fields>.mapFields<To extends Struct.Fields>(f: (fields: Fields) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<Simplify<Readonly<To>>>
To>>>
}
function function makeStruct<
Fields extends Struct.Fields
>(
ast: SchemaAST.Objects,
fields: Fields
): Struct<Fields>
makeStruct<const function (type parameter) Fields in makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields>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>(ast: SchemaAST.Objects(parameter) 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.class Objectsclass Objects {
_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 node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects, fields: const Fields extends Struct.Fieldsfields: function (type parameter) Fields in makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields>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<function (type parameter) Fields in makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields>Fields> {
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(ast: SchemaAST.Objects(parameter) 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, {
fields: const Fields extends Struct.Fieldsfields,
mapFields<To extends Struct.Fields>(this: Struct<Fields>, f: (fields: Fields) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined): Struct<To>mapFields<function (type parameter) To in mapFields<To extends Struct.Fields>(this: Struct<Fields>, f: (fields: Fields) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<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>(
this: Struct<Fields>(parameter) this: {
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: 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.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<Fields>>, readonly []>) => Struct<Fields>;
annotateKey: (annotations: Annotations.Key<Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<Fields>>>) => Struct<Fields>;
check: (checks_0: SchemaAST.Check<Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<Fields>>>, ...checks: Array<SchemaAST.Check<Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<…;
rebuild: (ast: SchemaAST.Objects) => Struct<Fields>;
make: (input: Struct.MakeInView<Fields, Struct.TypeOptionalKeys<Fields> | Struct.TypeConstructorDefaultedKeys<Fields>>, options?: MakeOptions) => Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<Fields>>;
makeOption: (input: Struct.MakeInView<Fields, Struct.TypeOptionalKeys<Fields> | Struct.TypeConstructorDefaultedKeys<Fields>>, options?: MakeOptions) => Option_.Option<Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<…;
makeEffect: (input: Struct.MakeInView<Fields, Struct.TypeOptionalKeys<Fields> | Struct.TypeConstructorDefaultedKeys<Fields>>, options?: MakeOptions) => Effect.Effect<Struct.View<Fields, 'Type', Struct.TypeOptionalKeys<Fields>, Struct.TypeMutableKeys<F…;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
this: interface 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 makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields>Fields>,
f: (fields: Fields) => Tof: (fields: const Fields extends Struct.Fieldsfields: function (type parameter) Fields in makeStruct<const Fields extends Struct.Fields>(ast: SchemaAST.Objects, fields: Fields): Struct<Fields>Fields) => function (type parameter) To in mapFields<To extends Struct.Fields>(this: Struct<Fields>, f: (fields: Fields) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<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<function (type parameter) To in mapFields<To extends Struct.Fields>(this: Struct<Fields>, f: (fields: Fields) => To, options?: {
readonly unsafePreserveChecks?: boolean | undefined;
} | undefined): Struct<To>
To> {
const const fields: To extends Struct.Fieldsfields = f: (fields: Fields) => Tof(this.Struct<Fields>.fields: const Fields extends 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)
return function makeStruct<
Fields extends Struct.Fields
>(
ast: SchemaAST.Objects,
fields: Fields
): Struct<Fields>
makeStruct(import SchemaASTSchemaAST.function struct<
Fields extends Schema.Struct.Fields
>(
fields: Fields,
checks: Checks | undefined,
annotations?: Schema.Annotations.Annotations
): Objects
struct(const fields: To extends Struct.Fieldsfields, options: | {
readonly unsafePreserveChecks?:
| boolean
| undefined
}
| undefined
options?.unsafePreserveChecks?: boolean | undefinedunsafePreserveChecks ? this.Bottom<unknown, unknown, unknown, unknown, Objects, Struct<Fields>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">["ast"]: SchemaAST.Objects(property) Bottom<unknown, unknown, unknown, unknown, Objects, Struct<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 : var undefinedundefined), const fields: To extends Struct.Fieldsfields)
}
})
}
/**
* Defines a struct schema from a map of field schemas.
*
* **Details**
*
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
* mark fields as optional, and {@link 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)
*
* ```ts
* 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 }
* ```
*
* @category constructors
* @since 3.10.0
*/
export function 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<const function (type parameter) Fields in Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields>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 Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields>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<function (type parameter) Fields in Struct<const Fields extends Struct.Fields>(fields: Fields): Struct<Fields>Fields> {
return function makeStruct<
Fields extends Struct.Fields
>(
ast: SchemaAST.Objects,
fields: Fields
): Struct<Fields>
makeStruct(import SchemaASTSchemaAST.function struct<
Fields extends Schema.Struct.Fields
>(
fields: Fields,
checks: Checks | undefined,
annotations?: Schema.Annotations.Annotations
): Objects
struct(fields: const Fields extends Struct.Fieldsfields, var undefinedundefined), fields: const Fields extends Struct.Fieldsfields)
}