<S extends Schema.Top = Schema.Top>(
document: Document,
options?: { readonly reviver?: Reviver<Schema.Top> | undefined }
): SCreates a runtime Schema from a Document.
When to use
Use when you have a serialized or computed schema representation document and need a runtime Schema for decoding/encoding.
Details
Pass options.reviver, such as toSchemaDefaultReviver, to handle
Declaration nodes for types like Date and Option. Without a
reviver, declarations fall back to their encodedSchema. Circular references
are handled via lazy Schema.suspend.
Gotchas
This throws if a $ref is not found in document.references.
Example (Reconstructing a Schema)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(
Schema.Struct({ name: Schema.String }).ast
)
const schema = SchemaRepresentation.toSchema(doc)
console.log(JSON.stringify(Schema.toJsonSchemaDocument(schema), null, 2))export function function toSchema<
S extends Schema.Top = Schema.Top
>(
document: Document,
options?: {
readonly reviver?:
| Reviver<Schema.Top>
| undefined
}
): S
Creates a runtime Schema from a
Document
.
When to use
Use when you have a serialized or computed schema representation document and
need a runtime Schema for decoding/encoding.
Details
Pass options.reviver, such as
toSchemaDefaultReviver
, to handle
Declaration
nodes for types like Date and Option. Without a
reviver, declarations fall back to their encodedSchema. Circular references
are handled via lazy Schema.suspend.
Gotchas
This throws if a $ref is not found in document.references.
Example (Reconstructing a Schema)
import { Schema, SchemaRepresentation } from "effect"
const doc = SchemaRepresentation.fromAST(
Schema.Struct({ name: Schema.String }).ast
)
const schema = SchemaRepresentation.toSchema(doc)
console.log(JSON.stringify(Schema.toJsonSchemaDocument(schema), null, 2))
toSchema<function (type parameter) S in toSchema<S extends Schema.Top = Schema.Top>(document: Document, options?: {
readonly reviver?: Reviver<Schema.Top> | undefined;
}): S
S extends import SchemaSchema.Top = import SchemaSchema.Top>(document: Document(parameter) document: {
representation: Representation;
references: References;
}
document: type Document = {
readonly representation: Representation
readonly references: References
}
A single
Representation
together with its named
References
.
When to use
Use when representing a single Schema AST together with its named references
before reconstructing a runtime Schema, converting to JSON Schema, or
wrapping it as a
MultiDocument
.
Document, options: {
readonly reviver?:
| Reviver<Schema.Top>
| undefined
}
options?: {
readonly reviver?: Reviver<Schema.Top> | undefinedreviver?: type Reviver<T> = (
declaration: Declaration,
recur: (representation: Representation) => T
) => T | undefined
A callback that handles
Declaration
nodes during reconstruction
(
toSchema
) or code generation (
toCodeDocument
).
Details
Return a value to handle the declaration. Return undefined to fall back to
default behavior, which uses encodedSchema for toSchema or the
generation annotation for toCodeDocument. recur processes child
representations recursively.
Reviver<import SchemaSchema.Top> | undefined
}): function (type parameter) S in toSchema<S extends Schema.Top = Schema.Top>(document: Document, options?: {
readonly reviver?: Reviver<Schema.Top> | undefined;
}): S
S {
type type Slot = {
state: 0 | 1 | 2
value: Schema.Top | undefined
ref: Schema.Top
}
Slot = {
// 0 = not started, 1 = building, 2 = done
state: 0 | 2 | 1state: 0 | 1 | 2
value: Schema.Top | undefinedvalue: import SchemaSchema.Top | undefined
ref: Schema.Top(property) ref: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
ref: import SchemaSchema.Top
}
const const slots: Map<string, Slot>slots = new var Map: MapConstructor
new <string, Slot>(iterable?: Iterable<readonly [string, Slot]> | null | undefined) => Map<string, Slot> (+3 overloads)
Map<string, type Slot = {
state: 0 | 1 | 2
value: Schema.Top | undefined
ref: Schema.Top
}
Slot>()
return function (local function) recur(r: Representation): Schema.Toprecur(document: Document(parameter) document: {
representation: Representation;
references: References;
}
document.representation: Representationrepresentation) as function (type parameter) S in toSchema<S extends Schema.Top = Schema.Top>(document: Document, options?: {
readonly reviver?: Reviver<Schema.Top> | undefined;
}): S
S
function function (local function) recur(r: Representation): Schema.Toprecur(r: Representationr: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation): import SchemaSchema.Top {
let let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out = function (local function) on(r: Representation): Schema.Topon(r: Representationr)
if ("annotations" in r: Representationr && r: Representationr.annotations?: | Schema.Annotations.Annotations
| undefined
annotations) let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out = let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>.annotate(annotations: Schema.Annotations.Bottom<unknown, any>): Schema.Topannotate(r: Representationr.annotations?: Schema.Annotations.Annotationsannotations)
let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out = function (local function) toSchemaChecks(top: Schema.Top, schema: Representation): Schema.ToptoSchemaChecks(let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out, r: Representationr)
return let out: Schema.Toplet out: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
out
}
function function (local function) getSlot(identifier: string): SlotgetSlot(identifier: stringidentifier: string): type Slot = {
state: 0 | 1 | 2
value: Schema.Top | undefined
ref: Schema.Top
}
Slot {
const const existing: Slot | undefinedexisting = const slots: Map<string, Slot>slots.Map<string, Slot>.get(key: string): Slot | undefinedReturns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.
get(identifier: stringidentifier)
if (const existing: Slot | undefinedexisting) return const existing: Slotconst existing: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
existing
// Create the slot *before* resolving, so self-references can see it.
const const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot: type Slot = {
state: 0 | 1 | 2
value: Schema.Top | undefined
ref: Schema.Top
}
Slot = {
state: 0 | 2 | 1state: 0,
value: Schema.Top | undefinedvalue: var undefinedundefined,
ref: Schema.suspend<
Schema.Top | Schema.Unknown
>
(property) ref: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.suspend<Schema.Top | Schema.Unknown>;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.suspend<Schema.Top | Schema.Unknown>;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.suspend<Schema.Top | Schema.Unknown>;
rebuild: (ast: SchemaAST.Suspend) => Schema.suspend<Schema.Top | Schema.Unknown>;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
ref: import SchemaSchema.function suspend<S extends Constraint>(
f: () => S
): suspend<S>
Creates a suspended schema that defers evaluation until needed. This is
essential for creating recursive schemas where a schema references itself,
preventing infinite recursion during schema definition.
Example (Defining recursive tree schemas)
import { Schema } from "effect"
interface Tree {
readonly value: number
readonly children: ReadonlyArray<Tree>
}
const Tree = Schema.Struct({
value: Schema.Number,
children: Schema.Array(Schema.suspend((): Schema.Codec<Tree> => Tree))
})
suspend(() => {
if (const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefinedvalue === var undefinedundefined) {
return import SchemaSchema.const Unknown: Unknownconst Unknown: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, readonly []>) => Schema.Unknown;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Unknown;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Unknown;
rebuild: (ast: SchemaAST.Unknown) => Schema.Unknown;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
Type-level representation of
Unknown
.
Schema for the unknown type. Accepts any value without validation.
When to use
Use as a top schema when you need to accept any input while preserving
TypeScript's unknown safety at use sites.
Unknown
}
return const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefined(property) value: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
value
})
}
const slots: Map<string, Slot>slots.Map<string, Slot>.set(key: string, value: Slot): Map<string, Slot>Adds a new element with a specified key and value to the Map. If an element with the same key already exists, the element will be updated.
set(identifier: stringidentifier, const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot)
return const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot
}
function function (local function) resolveReference($ref: string): Schema.TopresolveReference($ref: string$ref: string): import SchemaSchema.Top {
const const definition: Representationdefinition = document: Document(parameter) document: {
representation: Representation;
references: References;
}
document.references: Referencesreferences[$ref: string$ref]
if (const definition: Representationdefinition === var undefinedundefined) {
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error(`Reference ${$ref: string$ref} not found`)
}
const const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot = function (local function) getSlot(identifier: string): SlotgetSlot($ref: string$ref)
if (const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.state: 0 | 2 | 1state === 2) {
// Already built: return the built schema directly
return const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefinedvalue!
}
if (const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.state: 0 | 1state === 1) {
// Circular: we're currently building this identifier.
return const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.ref: Schema.Top(property) ref: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
ref
}
// First time: build it.
const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.state: 0 | 2 | 1state = 1
try {
const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefinedvalue = function (local function) recur(r: Representation): Schema.Toprecur(const definition: Representationdefinition)
const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.state: 0 | 2 | 1state = 2
return const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefined(property) value: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
value
} catch (function (local var) e: unknowne) {
// Leave the slot in a safe state so future thunks don't silently succeed.
const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.state: 0 | 2 | 1state = 0
const slot: Slotconst slot: {
state: 0 | 1 | 2;
value: Schema.Top | undefined;
ref: Schema.Top;
}
slot.value: Schema.Top | undefinedvalue = var undefinedundefined
throw function (local var) e: unknowne
}
}
function function (local function) on(r: Representation): Schema.Topon(r: Representationr: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation): import SchemaSchema.Top {
switch (r: Representationr._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag) {
case "Declaration":
return options: {
readonly reviver?:
| Reviver<Schema.Top>
| undefined
}
options?.reviver?: Reviver<Schema.Top> | undefinedreviver?.(r: Representation(parameter) r: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
r, function (local function) recur(r: Representation): Schema.Toprecur) ?? function (local function) recur(r: Representation): Schema.Toprecur(r: Representation(parameter) r: {
_tag: "Declaration";
annotations: Schema.Annotations.Annotations | undefined;
typeParameters: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<DeclarationMeta>>;
encodedSchema: Representation;
}
r.Declaration.encodedSchema: RepresentationencodedSchema)
case "Reference":
return function (local function) resolveReference($ref: string): Schema.TopresolveReference(r: Representation(parameter) r: {
_tag: "Reference";
$ref: string;
}
r.Reference.$ref: string$ref)
case "Suspend":
return function (local function) recur(r: Representation): Schema.Toprecur(r: Representation(parameter) r: {
_tag: "Suspend";
annotations: Schema.Annotations.Annotations | undefined;
checks: readonly [];
thunk: Representation;
}
r.Suspend.thunk: Representationthunk)
case "Null":
return import SchemaSchema.const Null: Nullconst Null: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<null, readonly []>) => Schema.Null;
annotateKey: (annotations: Schema.Annotations.Key<null>) => Schema.Null;
check: (checks_0: SchemaAST.Check<null>, ...checks: Array<SchemaAST.Check<null>>) => Schema.Null;
rebuild: (ast: SchemaAST.Null) => Schema.Null;
make: (input: null, options?: MakeOptions) => null;
makeOption: (input: null, options?: MakeOptions) => Option_.Option<null>;
makeEffect: (input: null, options?: MakeOptions) => Effect.Effect<null, 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; <…;
}
Type-level representation of
Null
.
Schema for the null literal. Validates that the input is strictly null.
Null
case "Undefined":
return import SchemaSchema.const Undefined: Undefinedconst Undefined: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<undefined, readonly []>) => Schema.Undefined;
annotateKey: (annotations: Schema.Annotations.Key<undefined>) => Schema.Undefined;
check: (checks_0: SchemaAST.Check<undefined>, ...checks: Array<SchemaAST.Check<undefined>>) => Schema.Undefined;
rebuild: (ast: SchemaAST.Undefined) => Schema.Undefined;
make: (input: undefined, options?: MakeOptions) => undefined;
makeOption: (input: undefined, options?: MakeOptions) => Option_.Option<undefined>;
makeEffect: (input: undefined, options?: MakeOptions) => Effect.Effect<undefined, 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; <…;
}
Type-level representation of
Undefined
.
Schema for the undefined literal. Validates that the input is strictly undefined.
Undefined
case "Void":
return import SchemaSchema.const Void: Voidconst Void: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<void, readonly []>) => Schema.Void;
annotateKey: (annotations: Schema.Annotations.Key<void>) => Schema.Void;
check: (checks_0: SchemaAST.Check<void>, ...checks: Array<SchemaAST.Check<void>>) => Schema.Void;
rebuild: (ast: SchemaAST.Void) => Schema.Void;
make: (input: void, options?: MakeOptions) => void;
makeOption: (input: void, options?: MakeOptions) => Option_.Option<void>;
makeEffect: (input: void, options?: MakeOptions) => Effect.Effect<void, 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; <…;
}
Type-level representation of
Void
.
Schema for a TypeScript void return value.
When to use
Use when you need to model the return value of a function, RPC, or endpoint
whose result is intentionally ignored.
Details
Runtime parsing accepts any present value and discards it, producing
undefined. The public decoded and encoded TypeScript representation remains
void, so typed construction, decoding, and encoding APIs are still modeled
as void.
Void
case "Never":
return import SchemaSchema.const Never: Neverconst Never: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<never, readonly []>) => Schema.Never;
annotateKey: (annotations: Schema.Annotations.Key<never>) => Schema.Never;
check: (checks_0: SchemaAST.Check<never>, ...checks: Array<SchemaAST.Check<never>>) => Schema.Never;
rebuild: (ast: SchemaAST.Never) => Schema.Never;
make: (input: never, options?: MakeOptions) => never;
makeOption: (input: never, options?: MakeOptions) => Option_.Option<never>;
makeEffect: (input: never, options?: MakeOptions) => Effect.Effect<never, 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; <…;
}
Type-level representation of
Never
.
Schema for the never type. Always fails validation — no value satisfies it.
Never
case "Unknown":
return import SchemaSchema.const Unknown: Unknownconst Unknown: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, readonly []>) => Schema.Unknown;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Unknown;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Unknown;
rebuild: (ast: SchemaAST.Unknown) => Schema.Unknown;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
Type-level representation of
Unknown
.
Schema for the unknown type. Accepts any value without validation.
When to use
Use as a top schema when you need to accept any input while preserving
TypeScript's unknown safety at use sites.
Unknown
case "Any":
return import SchemaSchema.const Any: Anyconst Any: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<any, readonly []>) => Schema.Any;
annotateKey: (annotations: Schema.Annotations.Key<any>) => Schema.Any;
check: (checks_0: SchemaAST.Check<any>, ...checks: Array<SchemaAST.Check<any>>) => Schema.Any;
rebuild: (ast: SchemaAST.Any) => Schema.Any;
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; <…;
}
Type-level representation of
Any
.
Schema for the any type. Accepts any value without validation.
Any
case "String": {
const const contentMediaType: string | undefinedcontentMediaType = r: Representation(parameter) r: {
_tag: "String";
annotations: Schema.Annotations.Annotations | undefined;
checks: ReadonlyArray<Check<StringMeta>>;
contentMediaType: string | undefined;
contentSchema: Representation | undefined;
}
r.String.contentMediaType?: string | undefinedcontentMediaType
const const contentSchema:
| Representation
| undefined
contentSchema = r: Representation(parameter) r: {
_tag: "String";
annotations: Schema.Annotations.Annotations | undefined;
checks: ReadonlyArray<Check<StringMeta>>;
contentMediaType: string | undefined;
contentSchema: Representation | undefined;
}
r.String.contentSchema?: Representation | undefinedcontentSchema
if (const contentMediaType: string | undefinedcontentMediaType === "application/json" && const contentSchema:
| Representation
| undefined
contentSchema !== var undefinedundefined) {
return import SchemaSchema.function fromJsonString<
S extends Constraint
>(schema: S): fromJsonString<S>
Returns a schema that decodes a JSON string and then decodes the parsed value
using the given schema.
Details
This is useful when working with JSON-encoded strings where the actual
structure of the value is known and described by an existing schema.
The resulting schema first parses the input string as JSON, and then runs the
provided schema on the parsed result.
JSON Schema generation:
When using fromJsonString with draft-2020-12 or openApi3.1, the
resulting schema will be a JSON Schema with a contentSchema property that
contains the JSON Schema for the given schema.
Example (Decoding JSON strings with a schema)
import { Schema } from "effect"
const schema = Schema.Struct({ a: Schema.Number })
const schemaFromJsonString = Schema.fromJsonString(schema)
Schema.decodeUnknownSync(schemaFromJsonString)(`{"a":1,"b":2}`)
// => { a: 1 }
Example (Emitting JSON Schema for a JSON string decoder)
import { Schema } from "effect"
const original = Schema.Struct({ a: Schema.String })
const schema = Schema.fromJsonString(original)
const document = Schema.toJsonSchemaDocument(schema)
console.log(JSON.stringify(document, null, 2))
// {
// "source": "draft-2020-12",
// "schema": {
// "type": "string",
// "contentMediaType": "application/json",
// "contentSchema": {
// "type": "object",
// "properties": {
// "a": {
// "type": "string"
// }
// },
// "required": [
// "a"
// ],
// "additionalProperties": false
// }
// },
// "definitions": {}
// }
fromJsonString(function (local function) recur(r: Representation): Schema.Toprecur(const contentSchema: RepresentationcontentSchema))
}
return import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, 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; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String
}
case "Number":
return import SchemaSchema.const Number: Numberconst Number: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<number, readonly []>) => Schema.Number;
annotateKey: (annotations: Schema.Annotations.Key<number>) => Schema.Number;
check: (checks_0: SchemaAST.Check<number>, ...checks: Array<SchemaAST.Check<number>>) => Schema.Number;
rebuild: (ast: SchemaAST.Number) => Schema.Number;
make: (input: number, options?: MakeOptions) => number;
makeOption: (input: number, options?: MakeOptions) => Option_.Option<number>;
makeEffect: (input: number, options?: MakeOptions) => Effect.Effect<number, 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; <…;
}
Type-level representation of
Number
.
Schema for number values, including NaN, Infinity, and -Infinity.
Details
Default JSON serializer:
- Finite numbers are serialized as numbers.
- Non-finite values are serialized as strings (
"NaN", "Infinity", "-Infinity").
Number
case "Boolean":
return import SchemaSchema.const Boolean: Booleanconst Boolean: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.Boolean;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.Boolean;
check: (checks_0: SchemaAST.Check<boolean>, ...checks: Array<SchemaAST.Check<boolean>>) => Schema.Boolean;
rebuild: (ast: SchemaAST.Boolean) => Schema.Boolean;
make: (input: boolean, options?: MakeOptions) => boolean;
makeOption: (input: boolean, options?: MakeOptions) => Option_.Option<boolean>;
makeEffect: (input: boolean, options?: MakeOptions) => Effect.Effect<boolean, 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; <…;
}
Type-level representation of
Boolean
.
Schema for boolean values. Validates that the input is typeof "boolean".
When to use
Use to validate values that are already JavaScript booleans.
Boolean
case "BigInt":
return import SchemaSchema.const BigInt: BigIntconst BigInt: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<bigint, readonly []>) => Schema.BigInt;
annotateKey: (annotations: Schema.Annotations.Key<bigint>) => Schema.BigInt;
check: (checks_0: SchemaAST.Check<bigint>, ...checks: Array<SchemaAST.Check<bigint>>) => Schema.BigInt;
rebuild: (ast: SchemaAST.BigInt) => Schema.BigInt;
make: (input: bigint, options?: MakeOptions) => bigint;
makeOption: (input: bigint, options?: MakeOptions) => Option_.Option<bigint>;
makeEffect: (input: bigint, options?: MakeOptions) => Effect.Effect<bigint, 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; <…;
}
Type-level representation of
BigInt
.
Schema for bigint values. Validates that the input is typeof "bigint".
When to use
Use when the input is already a bigint and the schema should validate and
preserve bigint values without parsing from another representation.
BigInt
case "Symbol":
return import SchemaSchema.const Symbol: Symbolconst Symbol: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<symbol, readonly []>) => Schema.Symbol;
annotateKey: (annotations: Schema.Annotations.Key<symbol>) => Schema.Symbol;
check: (checks_0: SchemaAST.Check<symbol>, ...checks: Array<SchemaAST.Check<symbol>>) => Schema.Symbol;
rebuild: (ast: SchemaAST.Symbol) => Schema.Symbol;
make: (input: symbol, options?: MakeOptions) => symbol;
makeOption: (input: symbol, options?: MakeOptions) => Option_.Option<symbol>;
makeEffect: (input: symbol, options?: MakeOptions) => Effect.Effect<symbol, 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; <…;
}
Type-level representation of
Symbol
.
Schema for symbol values. Validates that the input is typeof "symbol".
Symbol
case "Literal":
return import SchemaSchema.function Literal<
L extends SchemaAST.LiteralValue
>(literal: L): Literal<L>
Creates a schema for a single literal value (string, number, bigint, boolean, or null).
Example (Defining a string literal)
import { Schema } from "effect"
const schema = Schema.Literal("hello")
// Type: Schema.Literal<"hello">
Literal(r: Representation(parameter) r: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
r.Literal.literal: string | number | bigint | booleanliteral)
case "UniqueSymbol":
return import SchemaSchema.function UniqueSymbol<sym extends symbol>(
symbol: sym
): UniqueSymbol<sym>
Creates a schema for a specific symbol. Only that exact symbol satisfies the schema.
Example (Defining a specific symbol)
import { Schema } from "effect"
const mySymbol = Symbol.for("mySymbol")
const schema = Schema.UniqueSymbol(mySymbol)
UniqueSymbol(r: Representation(parameter) r: {
_tag: "UniqueSymbol";
annotations: Schema.Annotations.Annotations | undefined;
symbol: symbol;
}
r.UniqueSymbol.symbol: symbolsymbol)
case "ObjectKeyword":
return import SchemaSchema.const ObjectKeyword: ObjectKeywordconst ObjectKeyword: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<object, readonly []>) => Schema.ObjectKeyword;
annotateKey: (annotations: Schema.Annotations.Key<object>) => Schema.ObjectKeyword;
check: (checks_0: SchemaAST.Check<object>, ...checks: Array<SchemaAST.Check<object>>) => Schema.ObjectKeyword;
rebuild: (ast: SchemaAST.ObjectKeyword) => Schema.ObjectKeyword;
make: (input: object, options?: MakeOptions) => object;
makeOption: (input: object, options?: MakeOptions) => Option_.Option<object>;
makeEffect: (input: object, options?: MakeOptions) => Effect.Effect<object, 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; <…;
}
Type-level representation of
ObjectKeyword
.
Schema for the object type. Validates that the input is a non-null object or function
(i.e. typeof value === "object" && value !== null || typeof value === "function").
ObjectKeyword
case "Enum":
return import SchemaSchema.function Enum<
A extends { [x: string]: string | number }
>(enums: A): Enum<A>
Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"
Enum(var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.fromEntries<string | number>(entries: Iterable<readonly [PropertyKey, string | number]>): {
[k: string]: string | number;
} (+1 overload)
Returns an object created by key-value entries for properties and methods
fromEntries(r: Representation(parameter) r: {
_tag: "Enum";
annotations: Schema.Annotations.Annotations | undefined;
enums: ReadonlyArray<readonly [string, string | number]>;
}
r.Enum.enums: readonly (readonly [string, string | number])[]enums))
case "TemplateLiteral": {
const const parts: Schema.TemplateLiteral.Partsconst parts: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Schema.TemplateLiteral.Part>>): Array<Schema.TemplateLiteral.Part>; (...items: Array<Schema.TemplateLiteral.Part | ConcatArray<Schema.TemplateLiteral.Part>>): Array<Schema.TemplateLiteral.Part> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Schema.TemplateLiteral.Part>;
indexOf: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => number;
every: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array…;
some: (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyAr…;
reduce: { (callbackfn: (previousValue: Schema.TemplateLiteral.Part, currentValue: Schema.TemplateLiteral.Part, currentIndex: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => Schema.TemplateLiteral.Part): Schema.TemplateLiteral.Part; (…;
reduceRight: { (callbackfn: (previousValue: Schema.TemplateLiteral.Part, currentValue: Schema.TemplateLiteral.Part, currentIndex: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => Schema.TemplateLiteral.Part): Schema.TemplateLiteral.Part; (…;
find: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyA…;
findIndex: (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Schema.TemplateLiteral.Part]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.TemplateLiteral.Part>;
includes: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.TemplateLiteral.Part, index: number, array: Array<Schema.TemplateLiteral.Part>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.TemplateLiteral.Part | undefined;
findLast: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: Reado…;
findLastIndex: (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.TemplateLiteral.Part>;
toSorted: (compareFn?: ((a: Schema.TemplateLiteral.Part, b: Schema.TemplateLiteral.Part) => number) | undefined) => Array<Schema.TemplateLiteral.Part>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.TemplateLiteral.Part>): Array<Schema.TemplateLiteral.Part>; (start: number, deleteCount?: number): Array<Schema.TemplateLiteral.Part> };
with: (index: number, value: Schema.TemplateLiteral.Part) => Array<Schema.TemplateLiteral.Part>;
}
parts = r: Representation(parameter) r: {
_tag: "TemplateLiteral";
annotations: Schema.Annotations.Annotations | undefined;
parts: ReadonlyArray<Representation>;
}
r.TemplateLiteral.parts: ReadonlyArray<Representation>parts.ReadonlyArray<Representation>.map<Schema.Top>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Schema.Top, thisArg?: any): Schema.Top[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(r: Representation): Schema.Toprecur) as import SchemaSchema.TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Parts = readonly Schema.TemplateLiteral.Part[]Ordered list of parts used to construct a TemplateLiteral schema.
Parts
return import SchemaSchema.function TemplateLiteral<
Parts extends TemplateLiteral.Parts
>(parts: Parts): TemplateLiteral<Parts>
Creates a schema that validates strings by matching ordered template literal
parts.
When to use
Use when the decoded value should remain the matched string and you do not
need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.
TemplateLiteral(const parts: Schema.TemplateLiteral.Partsconst parts: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Schema.TemplateLiteral.Part>>): Array<Schema.TemplateLiteral.Part>; (...items: Array<Schema.TemplateLiteral.Part | ConcatArray<Schema.TemplateLiteral.Part>>): Array<Schema.TemplateLiteral.Part> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Schema.TemplateLiteral.Part>;
indexOf: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => number;
every: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array…;
some: (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyAr…;
reduce: { (callbackfn: (previousValue: Schema.TemplateLiteral.Part, currentValue: Schema.TemplateLiteral.Part, currentIndex: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => Schema.TemplateLiteral.Part): Schema.TemplateLiteral.Part; (…;
reduceRight: { (callbackfn: (previousValue: Schema.TemplateLiteral.Part, currentValue: Schema.TemplateLiteral.Part, currentIndex: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => Schema.TemplateLiteral.Part): Schema.TemplateLiteral.Part; (…;
find: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyA…;
findIndex: (predicate: (value: Schema.TemplateLiteral.Part, index: number, obj: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Schema.TemplateLiteral.Part]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.TemplateLiteral.Part>;
includes: (searchElement: Schema.TemplateLiteral.Part, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.TemplateLiteral.Part, index: number, array: Array<Schema.TemplateLiteral.Part>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.TemplateLiteral.Part | undefined;
findLast: { (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: Reado…;
findLastIndex: (predicate: (value: Schema.TemplateLiteral.Part, index: number, array: ReadonlyArray<Schema.TemplateLiteral.Part>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.TemplateLiteral.Part>;
toSorted: (compareFn?: ((a: Schema.TemplateLiteral.Part, b: Schema.TemplateLiteral.Part) => number) | undefined) => Array<Schema.TemplateLiteral.Part>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.TemplateLiteral.Part>): Array<Schema.TemplateLiteral.Part>; (start: number, deleteCount?: number): Array<Schema.TemplateLiteral.Part> };
with: (index: number, value: Schema.TemplateLiteral.Part) => Array<Schema.TemplateLiteral.Part>;
}
parts)
}
case "Arrays": {
const const elements: Array<Schema.Top>elements = r: Representation(parameter) r: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
r.Arrays.elements: ReadonlyArray<Element>elements.ReadonlyArray<Element>.map<Schema.Top>(callbackfn: (value: Element, index: number, array: readonly Element[]) => Schema.Top, thisArg?: any): Schema.Top[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e) => {
const const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s = function (local function) recur(r: Representation): Schema.Toprecur(e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e.Element.type: Representationtype)
return e: Element(parameter) e: {
isOptional: boolean;
type: Representation;
annotations: Schema.Annotations.Annotations | undefined;
}
e.Element.isOptional: booleanisOptional ? import SchemaSchema.const optionalKey: optionalKeyLambda
<Schema.Top>(self: Schema.Top) => Schema.optionalKey<Schema.Top>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s) : const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s
})
const const rest: Array<Schema.Top>rest = r: Representation(parameter) r: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
r.Arrays.rest: ReadonlyArray<Representation>rest.ReadonlyArray<Representation>.map<Schema.Top>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Schema.Top, thisArg?: any): Schema.Top[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(r: Representation): Schema.Toprecur)
if (import ArrArr.const isArrayNonEmpty: <A>(
self: Array<A>
) => self is NonEmptyArray<A>
Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // true
isArrayNonEmpty(const rest: Array<Schema.Top>rest)) {
if (r: Representation(parameter) r: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
r.Arrays.elements: ReadonlyArray<Element>elements.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0 && r: Representation(parameter) r: {
_tag: "Arrays";
annotations: Schema.Annotations.Annotations | undefined;
elements: ReadonlyArray<Element>;
rest: ReadonlyArray<Representation>;
checks: ReadonlyArray<Check<ArraysMeta>>;
}
r.Arrays.rest: ReadonlyArray<Representation>rest.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 1) {
return import SchemaSchema.Array<Schema.Top>(self: Schema.Top): Schema.$Array<Schema.Top>
export Array
Defines a ReadonlyArray schema for a given element schema.
Example (Defining an array of strings)
import { Schema } from "effect"
const schema = Schema.Array(Schema.String)
const result = Schema.decodeUnknownSync(schema)(["a", "b", "c"])
console.log(result)
// [ 'a', 'b', 'c' ]
Array(const rest: [Schema.Top, ...Schema.Top[]]const rest: {
0: Schema.Top;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Schema.Top | undefined;
push: (...items: Array<Schema.Top>) => number;
concat: { (...items: Array<ConcatArray<Schema.Top>>): Array<Schema.Top>; (...items: Array<Schema.Top | ConcatArray<Schema.Top>>): Array<Schema.Top> };
join: (separator?: string) => string;
reverse: () => Array<Schema.Top>;
shift: () => Schema.Top | undefined;
slice: (start?: number, end?: number) => Array<Schema.Top>;
sort: (compareFn?: ((a: Schema.Top, b: Schema.Top) => number) | undefined) => [Schema.Top, ...Schema.Top[]];
splice: { (start: number, deleteCount?: number): Array<Schema.Top>; (start: number, deleteCount: number, ...items: Array<Schema.Top>): Array<Schema.Top> };
unshift: (...items: Array<Schema.Top>) => number;
indexOf: (searchElement: Schema.Top, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.Top, fromIndex?: number) => number;
every: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.Top, index: number, array: Array<Schema.Top>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.Top, index: number, array: Array<Schema.Top>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): Array<Schema.Top> };
reduce: { (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array: Array<Schema.Top>) => Schema.Top): Schema.Top; (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array…;
reduceRight: { (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array: Array<Schema.Top>) => Schema.Top): Schema.Top; (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array…;
find: { (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => unknown, thisArg?: any): Schema.Top | undefine…;
findIndex: (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => unknown, thisArg?: any) => number;
fill: (value: Schema.Top, start?: number, end?: number) => [Schema.Top, ...Schema.Top[]];
copyWithin: (target: number, start: number, end?: number) => [Schema.Top, ...Schema.Top[]];
entries: () => ArrayIterator<[number, Schema.Top]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.Top>;
includes: (searchElement: Schema.Top, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.Top, index: number, array: Array<Schema.Top>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.Top | undefined;
findLast: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): Schema.Top | unde…;
findLastIndex: (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.Top>;
toSorted: (compareFn?: ((a: Schema.Top, b: Schema.Top) => number) | undefined) => Array<Schema.Top>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.Top>): Array<Schema.Top>; (start: number, deleteCount?: number): Array<Schema.Top> };
with: (index: number, value: Schema.Top) => Array<Schema.Top>;
}
rest[0])
}
return import SchemaSchema.function TupleWithRest<
S extends Tuple<Tuple.Elements>,
Rest extends TupleWithRest.Rest
>(schema: S, rest: Rest): TupleWithRest<S, Rest>
Extends a fixed-length tuple schema with a variadic rest segment.
Details
The resulting tuple starts with the fixed elements from schema. The first
schema in rest is the repeatable element schema, and any additional schemas
in rest are required trailing tuple elements after the variadic segment. For
example, [Schema.Boolean, Schema.String] represents zero or more booleans
followed by a final string.
Example (Defining tuples with rest elements)
import { Schema } from "effect"
// [string, number, ...boolean[]]
const schema = Schema.TupleWithRest(
Schema.Tuple([Schema.String, Schema.Number]),
[Schema.Boolean]
)
const result = Schema.decodeUnknownSync(schema)(["hello", 1, true, false])
console.log(result)
// [ 'hello', 1, true, false ]
TupleWithRest(import SchemaSchema.function Tuple<
Elements extends ReadonlyArray<Constraint>
>(elements: Elements): Tuple<Elements>
Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Tuple(const elements: Array<Schema.Top>elements), const rest: [Schema.Top, ...Schema.Top[]]const rest: {
0: Schema.Top;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Schema.Top | undefined;
push: (...items: Array<Schema.Top>) => number;
concat: { (...items: Array<ConcatArray<Schema.Top>>): Array<Schema.Top>; (...items: Array<Schema.Top | ConcatArray<Schema.Top>>): Array<Schema.Top> };
join: (separator?: string) => string;
reverse: () => Array<Schema.Top>;
shift: () => Schema.Top | undefined;
slice: (start?: number, end?: number) => Array<Schema.Top>;
sort: (compareFn?: ((a: Schema.Top, b: Schema.Top) => number) | undefined) => [Schema.Top, ...Schema.Top[]];
splice: { (start: number, deleteCount?: number): Array<Schema.Top>; (start: number, deleteCount: number, ...items: Array<Schema.Top>): Array<Schema.Top> };
unshift: (...items: Array<Schema.Top>) => number;
indexOf: (searchElement: Schema.Top, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.Top, fromIndex?: number) => number;
every: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): boolean };
some: (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.Top, index: number, array: Array<Schema.Top>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.Top, index: number, array: Array<Schema.Top>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): Array<Schema.Top> };
reduce: { (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array: Array<Schema.Top>) => Schema.Top): Schema.Top; (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array…;
reduceRight: { (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array: Array<Schema.Top>) => Schema.Top): Schema.Top; (callbackfn: (previousValue: Schema.Top, currentValue: Schema.Top, currentIndex: number, array…;
find: { (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => unknown, thisArg?: any): Schema.Top | undefine…;
findIndex: (predicate: (value: Schema.Top, index: number, obj: Array<Schema.Top>) => unknown, thisArg?: any) => number;
fill: (value: Schema.Top, start?: number, end?: number) => [Schema.Top, ...Schema.Top[]];
copyWithin: (target: number, start: number, end?: number) => [Schema.Top, ...Schema.Top[]];
entries: () => ArrayIterator<[number, Schema.Top]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.Top>;
includes: (searchElement: Schema.Top, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.Top, index: number, array: Array<Schema.Top>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.Top | undefined;
findLast: { (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any): Schema.Top | unde…;
findLastIndex: (predicate: (value: Schema.Top, index: number, array: Array<Schema.Top>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.Top>;
toSorted: (compareFn?: ((a: Schema.Top, b: Schema.Top) => number) | undefined) => Array<Schema.Top>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.Top>): Array<Schema.Top>; (start: number, deleteCount?: number): Array<Schema.Top> };
with: (index: number, value: Schema.Top) => Array<Schema.Top>;
}
rest)
}
return import SchemaSchema.function Tuple<
Elements extends ReadonlyArray<Constraint>
>(elements: Elements): Tuple<Elements>
Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Tuple(const elements: Array<Schema.Top>elements)
}
case "Objects": {
const const fields: Record<
PropertyKey,
Schema.Top
>
fields: type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<type PropertyKey =
| string
| number
| symbol
PropertyKey, import SchemaSchema.Top> = {}
for (const const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
ps of r: Representation(parameter) r: {
_tag: "Objects";
annotations: Schema.Annotations.Annotations | undefined;
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
checks: ReadonlyArray<Check<ObjectsMeta>>;
}
r.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures) {
const const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s = function (local function) recur(r: Representation): Schema.Toprecur(const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
ps.PropertySignature.type: Representationtype)
const const withOptional: Schema.Topconst withOptional: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
withOptional = const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
ps.PropertySignature.isOptional: booleanisOptional ? import SchemaSchema.const optionalKey: optionalKeyLambda
<Schema.Top>(self: Schema.Top) => Schema.optionalKey<Schema.Top>
Type-level representation returned by
optionalKey
.
Creates an exact optional key schema for struct fields. Unlike optional,
this creates exact optional properties (not | undefined) that can be
completely omitted from the object.
Example (Creating a struct with optional key)
import { Schema } from "effect"
const schema = Schema.Struct({
name: Schema.String,
age: Schema.optionalKey(Schema.Number)
})
// Type: { readonly name: string; readonly age?: number }
type Person = typeof schema["Type"]
optionalKey(const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s) : const s: Schema.Topconst s: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
s
const fields: Record<
PropertyKey,
Schema.Top
>
fields[const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
ps.PropertySignature.name: PropertyKeyname] = const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: Representation;
isOptional: boolean;
isMutable: boolean;
annotations: Schema.Annotations.Annotations | undefined;
}
ps.PropertySignature.isMutable: booleanisMutable ? import SchemaSchema.const mutableKey: mutableKeyLambda
<Schema.Top>(self: Schema.Top) => Schema.mutableKey<Schema.Top>
Type-level representation returned by
mutableKey
.
Makes a struct field mutable (removes the readonly modifier on the property).
Use
readonlyKey
to reverse.
mutableKey(const withOptional: Schema.Topconst withOptional: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
withOptional) : const withOptional: Schema.Topconst withOptional: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
withOptional
}
const const indexSignatures: Array<
Schema.$Record<Schema.Record.Key, Schema.Top>
>
indexSignatures = r: Representation(parameter) r: {
_tag: "Objects";
annotations: Schema.Annotations.Annotations | undefined;
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
checks: ReadonlyArray<Check<ObjectsMeta>>;
}
r.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.ReadonlyArray<IndexSignature>.map<Schema.$Record<Schema.Record.Key, Schema.Top>>(callbackfn: (value: IndexSignature, index: number, array: readonly IndexSignature[]) => Schema.$Record<Schema.Record.Key, Schema.Top>, thisArg?: any): Schema.$Record<Schema.Record.Key, Schema.Top>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is) =>
import SchemaSchema.function Record<
Key extends Record.Key,
Value extends Constraint
>(
key: Key,
value: Value,
options?: {
readonly keyValueCombiner: {
readonly decode?:
| Combiner.Combiner<
readonly [Key["Type"], Value["Type"]]
>
| undefined
readonly encode?:
| Combiner.Combiner<
readonly [
Key["Encoded"],
Value["Encoded"]
]
>
| undefined
}
}
): $Record<Key, Value>
Defines a record schema whose dynamic properties are selected by a key schema
and decoded with a value schema.
Details
For dynamic keys, the key schema selects matching own properties and the
value schema decodes or encodes only those selected properties. Checks on
string, number, symbol, and template literal key schemas narrow which
properties are selected.
For transformed key schemas, property selection is based on encoded property
names before the selected key is decoded.
Example (Defining a string-keyed record of numbers)
import { Schema } from "effect"
const schema = Schema.Record(Schema.String, Schema.Number)
// { readonly [x: string]: number }
type R = typeof schema.Type
const result = Schema.decodeUnknownSync(schema)({ a: 1, b: 2 })
console.log(result)
// { a: 1, b: 2 }
Record(function (local function) recur(r: Representation): Schema.Toprecur(is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is.IndexSignature.parameter: Representationparameter) as import SchemaSchema.Record.interface Record.KeyConstraint for schemas that can be used as record keys.
Details
The key schema must decode and encode property keys (string, number, or
symbol) so it can describe object property names.
Key, function (local function) recur(r: Representation): Schema.Toprecur(is: IndexSignature(parameter) is: {
parameter: Representation;
type: Representation;
}
is.IndexSignature.type: Representationtype))
)
if (import ArrArr.const isArrayNonEmpty: <A>(
self: Array<A>
) => self is NonEmptyArray<A>
Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // true
isArrayNonEmpty(const indexSignatures: Array<
Schema.$Record<Schema.Record.Key, Schema.Top>
>
indexSignatures)) {
if (r: Representation(parameter) r: {
_tag: "Objects";
annotations: Schema.Annotations.Annotations | undefined;
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
checks: ReadonlyArray<Check<ObjectsMeta>>;
}
r.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0 && const indexSignatures: [
Schema.$Record<Schema.Record.Key, Schema.Top>,
...Schema.$Record<
Schema.Record.Key,
Schema.Top
>[]
]
const indexSignatures: {
0: Schema.$Record<Schema.Record.Key, Schema.Top>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
push: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
concat: { (...items: Array<ConcatArray<Schema.$Record<Schema.Record.Key, Schema.Top>>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top> | ConcatArray<Schema.$Record<Schema.Recor…;
join: (separator?: string) => string;
reverse: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
shift: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
slice: (start?: number, end?: number) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
sort: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[…;
splice: { (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Sc…;
unshift: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
indexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
every: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Schema.$Record<Schema.Record.K…;
some: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.$Record<Schema.Record.Key,…;
reduce: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
reduceRight: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
find: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record.K…;
findIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
fill: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, start?: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
copyWithin: (target: number, start: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
entries: () => ArrayIterator<[number, Schema.$Record<Schema.Record.Key, Schema.Top>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.$Record<Schema.Record.Key, Schema.Top>>;
includes: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
findLast: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record…;
findLastIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSorted: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Sc…;
with: (index: number, value: Schema.$Record<Schema.Record.Key, Schema.Top>) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
}
indexSignatures.length: numberlength === 1) {
return const indexSignatures: [
Schema.$Record<Schema.Record.Key, Schema.Top>,
...Schema.$Record<
Schema.Record.Key,
Schema.Top
>[]
]
const indexSignatures: {
0: Schema.$Record<Schema.Record.Key, Schema.Top>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
push: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
concat: { (...items: Array<ConcatArray<Schema.$Record<Schema.Record.Key, Schema.Top>>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top> | ConcatArray<Schema.$Record<Schema.Recor…;
join: (separator?: string) => string;
reverse: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
shift: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
slice: (start?: number, end?: number) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
sort: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[…;
splice: { (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Sc…;
unshift: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
indexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
every: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Schema.$Record<Schema.Record.K…;
some: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.$Record<Schema.Record.Key,…;
reduce: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
reduceRight: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
find: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record.K…;
findIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
fill: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, start?: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
copyWithin: (target: number, start: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
entries: () => ArrayIterator<[number, Schema.$Record<Schema.Record.Key, Schema.Top>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.$Record<Schema.Record.Key, Schema.Top>>;
includes: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
findLast: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record…;
findLastIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSorted: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Sc…;
with: (index: number, value: Schema.$Record<Schema.Record.Key, Schema.Top>) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
}
indexSignatures[0]
}
return import SchemaSchema.function StructWithRest<
S extends StructWithRest.Objects,
Records extends StructWithRest.Records
>(
schema: S,
records: Records
): StructWithRest<S, Records>
Extends a struct schema with one or more record (index-signature) schemas,
producing a schema whose decoded type intersects the struct and all records.
Gotchas
TypeScript index signatures also apply to fixed keys. StructWithRest does
not reject incompatible fixed fields at the call site; use
StructWithRest.ValidateRecords when you want an explicit type-level
compatibility check.
Example (Defining structs with string-indexed extra keys)
import { Schema } from "effect"
const schema = Schema.StructWithRest(
Schema.Struct({ id: Schema.Number }),
[Schema.Record(Schema.String, Schema.Number)]
)
// { readonly id: number, readonly [x: string]: number }
type T = typeof schema.Type
StructWithRest(import SchemaSchema.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 fields: Record<
PropertyKey,
Schema.Top
>
fields), const indexSignatures: [
Schema.$Record<Schema.Record.Key, Schema.Top>,
...Schema.$Record<
Schema.Record.Key,
Schema.Top
>[]
]
const indexSignatures: {
0: Schema.$Record<Schema.Record.Key, Schema.Top>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
push: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
concat: { (...items: Array<ConcatArray<Schema.$Record<Schema.Record.Key, Schema.Top>>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top> | ConcatArray<Schema.$Record<Schema.Recor…;
join: (separator?: string) => string;
reverse: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
shift: () => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
slice: (start?: number, end?: number) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
sort: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[…;
splice: { (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Sc…;
unshift: (...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => number;
indexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => number;
every: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Schema.$Record<Schema.Record.K…;
some: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Schema.$Record<Schema.Record.Key,…;
reduce: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
reduceRight: { (callbackfn: (previousValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentValue: Schema.$Record<Schema.Record.Key, Schema.Top>, currentIndex: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => Schema.$Record…;
find: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record.K…;
findIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, obj: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
fill: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, start?: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
copyWithin: (target: number, start: number, end?: number) => [Schema.$Record<Schema.Record.Key, Schema.Top>, ...Schema.$Record<Schema.Record.Key, Schema.Top>[]];
entries: () => ArrayIterator<[number, Schema.$Record<Schema.Record.Key, Schema.Top>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Schema.$Record<Schema.Record.Key, Schema.Top>>;
includes: (searchElement: Schema.$Record<Schema.Record.Key, Schema.Top>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Schema.$Record<Schema.Record.Key, Schema.Top> | undefined;
findLast: { (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Schema.$Record<Schema.Record…;
findLastIndex: (predicate: (value: Schema.$Record<Schema.Record.Key, Schema.Top>, index: number, array: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSorted: (compareFn?: ((a: Schema.$Record<Schema.Record.Key, Schema.Top>, b: Schema.$Record<Schema.Record.Key, Schema.Top>) => number) | undefined) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Schema.$Record<Schema.Record.Key, Schema.Top>>): Array<Schema.$Record<Schema.Record.Key, Schema.Top>>; (start: number, deleteCount?: number): Array<Schema.$Record<Schema.Record.Key, Sc…;
with: (index: number, value: Schema.$Record<Schema.Record.Key, Schema.Top>) => Array<Schema.$Record<Schema.Record.Key, Schema.Top>>;
}
indexSignatures)
}
return import SchemaSchema.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 fields: Record<
PropertyKey,
Schema.Top
>
fields)
}
case "Union": {
if (r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0) return import SchemaSchema.const Never: Neverconst Never: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<never, readonly []>) => Schema.Never;
annotateKey: (annotations: Schema.Annotations.Key<never>) => Schema.Never;
check: (checks_0: SchemaAST.Check<never>, ...checks: Array<SchemaAST.Check<never>>) => Schema.Never;
rebuild: (ast: SchemaAST.Never) => Schema.Never;
make: (input: never, options?: MakeOptions) => never;
makeOption: (input: never, options?: MakeOptions) => Option_.Option<never>;
makeEffect: (input: never, options?: MakeOptions) => Effect.Effect<never, 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; <…;
}
Type-level representation of
Never
.
Schema for the never type. Always fails validation — no value satisfies it.
Never
if (r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Representation>.every<Literal>(predicate: (value: Representation, index: number, array: readonly Representation[]) => value is Literal, thisArg?: any): this is readonly S[] (+1 overload)Determines whether all the members of an array satisfy the specified test.
every((t: Representationt) => t: Representationt._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag === "Literal")) {
if (r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 1) {
return import SchemaSchema.function Literal<
L extends SchemaAST.LiteralValue
>(literal: L): Literal<L>
Creates a schema for a single literal value (string, number, bigint, boolean, or null).
Example (Defining a string literal)
import { Schema } from "effect"
const schema = Schema.Literal("hello")
// Type: Schema.Literal<"hello">
Literal(r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types[0].Literal.literal: string | number | bigint | booleanliteral)
}
return import SchemaSchema.function Literals<
L extends ReadonlyArray<SchemaAST.LiteralValue>
>(literals: L): Literals<L>
Creates a union schema from an array of literal values.
Example (Defining status codes)
import { Schema } from "effect"
const schema = Schema.Literals(["active", "inactive", "pending"])
// accepts "active", "inactive", or "pending"
Literals(r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Literal>.map<string | number | bigint | boolean>(callbackfn: (value: Literal, index: number, array: readonly Literal[]) => string | number | bigint | boolean, thisArg?: any): (string | number | bigint | boolean)[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((t: Literal(parameter) t: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
t) => t: Literal(parameter) t: {
_tag: "Literal";
annotations: Schema.Annotations.Annotations | undefined;
literal: string | number | boolean | bigint;
}
t.Literal.literal: string | number | bigint | booleanliteral))
}
return import SchemaSchema.function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union(r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.types: ReadonlyArray<Representation>types.ReadonlyArray<Representation>.map<Schema.Top>(callbackfn: (value: Representation, index: number, array: readonly Representation[]) => Schema.Top, thisArg?: any): Schema.Top[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) recur(r: Representation): Schema.Toprecur), { mode?: "anyOf" | "oneOf" | undefinedmode: r: Representation(parameter) r: {
_tag: "Union";
annotations: Schema.Annotations.Annotations | undefined;
types: ReadonlyArray<Representation>;
mode: "anyOf" | "oneOf";
}
r.Union.mode: "anyOf" | "oneOf"mode })
}
}
}
function function (local function) toSchemaChecks(top: Schema.Top, schema: Representation): Schema.ToptoSchemaChecks(top: Schema.Top(parameter) top: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
top: import SchemaSchema.Top, schema: Representationschema: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation): import SchemaSchema.Top {
switch (schema: Representationschema._tag: | "Declaration"
| "Suspend"
| "Reference"
| "Null"
| "Undefined"
| "Void"
| "Never"
| "Unknown"
| "Any"
| "String"
| "Number"
| "Boolean"
| "BigInt"
| "Symbol"
| "Literal"
| "UniqueSymbol"
| "ObjectKeyword"
| "Enum"
| "TemplateLiteral"
| "Arrays"
| "Objects"
| "Union"
_tag) {
default:
return top: Schema.Top(parameter) top: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
top
case "String":
case "Number":
case "BigInt":
case "Arrays":
case "Objects":
case "Declaration": {
const const checks: Array<SchemaAST.Check<any>>checks = schema: Representationschema.checks: | readonly Check<DeclarationMeta>[]
| readonly Check<StringMeta>[]
| readonly Check<NumberMeta>[]
| readonly Check<BigIntMeta>[]
| readonly Check<ArraysMeta>[]
| readonly Check<ObjectsMeta>[]
checks.ReadonlyArray<T>.map<SchemaAST.Check<any>>(callbackfn: ((value: Check<DeclarationMeta>, index: number, array: readonly Check<DeclarationMeta>[]) => SchemaAST.Check<any>) & ((value: Check<StringMeta>, index: number, array: readonly Check<StringMeta>[]) => SchemaAST.Check<any>) & ((value: Check<NumberMeta>, index: number, array: readonly Check<NumberMeta>[]) => SchemaAST.Check<any>) & ((value: Check<BigIntMeta>, index: number, array: readonly Check<...>[]) => SchemaAST.Check<...>) & ((value: Check<...>, index: number, array: readonly Check<...>[]) => SchemaAST.Check<...>) & ((value: Check<...>, index: number, array: readonly Check<...>[]) => SchemaAST.Check<...>), thisArg?: any): SchemaAST.Check<...>[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(function (local function) toSchemaCheck(check: Check<Meta>): SchemaAST.Check<any>toSchemaCheck)
return import ArrArr.const isArrayNonEmpty: <A>(
self: Array<A>
) => self is NonEmptyArray<A>
Checks whether a mutable Array is non-empty, narrowing the type to
NonEmptyArray.
When to use
Use when you need the narrowed value to remain a mutable Array after proving
it has at least one element.
Example (Checking for a non-empty array)
import { Array } from "effect"
console.log(Array.isArrayNonEmpty([])) // false
console.log(Array.isArrayNonEmpty([1, 2, 3])) // true
isArrayNonEmpty(const checks: Array<SchemaAST.Check<any>>checks) ? top: Schema.Top(parameter) top: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
top.Bottom<unknown, unknown, unknown, unknown, AST, Top, unknown, unknown, any, unknown, Mutability, Optionality, ConstructorDefault, Mutability, Optionality>.check(checks_0: SchemaAST.Check<unknown>, ...checks: SchemaAST.Check<unknown>[]): Schema.Topcheck(...const checks: [
SchemaAST.Check<any>,
...SchemaAST.Check<any>[]
]
const checks: {
0: SchemaAST.Check<any>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => SchemaAST.Check<any> | undefined;
push: (...items: Array<SchemaAST.Check<any>>) => number;
concat: { (...items: Array<ConcatArray<SchemaAST.Check<any>>>): Array<SchemaAST.Check<any>>; (...items: Array<SchemaAST.Check<any> | ConcatArray<SchemaAST.Check<any>>>): Array<SchemaAST.Check<any>> };
join: (separator?: string) => string;
reverse: () => Array<SchemaAST.Check<any>>;
shift: () => SchemaAST.Check<any> | undefined;
slice: (start?: number, end?: number) => Array<SchemaAST.Check<any>>;
sort: (compareFn?: ((a: SchemaAST.Check<any>, b: SchemaAST.Check<any>) => number) | undefined) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
splice: { (start: number, deleteCount?: number): Array<SchemaAST.Check<any>>; (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<any>>): Array<SchemaAST.Check<any>> };
unshift: (...items: Array<SchemaAST.Check<any>>) => number;
indexOf: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => number;
every: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unkn…;
some: (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown…;
reduce: { (callbackfn: (previousValue: SchemaAST.Check<any>, currentValue: SchemaAST.Check<any>, currentIndex: number, array: Array<SchemaAST.Check<any>>) => SchemaAST.Check<any>): SchemaAST.Check<any>; (callbackfn: (previousValue: SchemaAST.Check…;
reduceRight: { (callbackfn: (previousValue: SchemaAST.Check<any>, currentValue: SchemaAST.Check<any>, currentIndex: number, array: Array<SchemaAST.Check<any>>) => SchemaAST.Check<any>): SchemaAST.Check<any>; (callbackfn: (previousValue: SchemaAST.Check…;
find: { (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => unknow…;
findIndex: (predicate: (value: SchemaAST.Check<any>, index: number, obj: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => number;
fill: (value: SchemaAST.Check<any>, start?: number, end?: number) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
copyWithin: (target: number, start: number, end?: number) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]];
entries: () => ArrayIterator<[number, SchemaAST.Check<any>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaAST.Check<any>>;
includes: (searchElement: SchemaAST.Check<any>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaAST.Check<any> | undefined;
findLast: { (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => un…;
findLastIndex: (predicate: (value: SchemaAST.Check<any>, index: number, array: Array<SchemaAST.Check<any>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaAST.Check<any>>;
toSorted: (compareFn?: ((a: SchemaAST.Check<any>, b: SchemaAST.Check<any>) => number) | undefined) => Array<SchemaAST.Check<any>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaAST.Check<any>>): Array<SchemaAST.Check<any>>; (start: number, deleteCount?: number): Array<SchemaAST.Check<any>> };
with: (index: number, value: SchemaAST.Check<any>) => Array<SchemaAST.Check<any>>;
}
checks) : top: Schema.Top(parameter) top: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<unknown, any>) => Schema.Top;
annotateKey: (annotations: Schema.Annotations.Key<unknown>) => Schema.Top;
check: (checks_0: SchemaAST.Check<unknown>, ...checks: Array<SchemaAST.Check<unknown>>) => Schema.Top;
rebuild: (ast: SchemaAST.AST) => Schema.Top;
make: (input: unknown, options?: MakeOptions) => unknown;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<unknown>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<unknown, 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; <…;
}
top
}
}
}
function function (local function) toSchemaCheck(check: Check<Meta>): SchemaAST.Check<any>toSchemaCheck(check: Check<Meta>check: type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>): import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<any> {
switch (check: Check<Meta>check._tag: "Filter" | "FilterGroup"_tag) {
case "Filter":
return function (local function) toSchemaFilter(filter: Filter<Meta>): SchemaAST.Check<any>toSchemaFilter(check: Check<Meta>(parameter) check: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
check)
case "FilterGroup": {
return import SchemaSchema.function makeFilterGroup<T>(
checks: readonly [
SchemaAST.Check<T>,
...Array<SchemaAST.Check<T>>
],
annotations?:
| Schema.Annotations.Filter
| undefined
): SchemaAST.FilterGroup<T>
Groups multiple checks into a single
SchemaAST.FilterGroup
, applying
optional shared annotations to the group as a whole.
makeFilterGroup(import ArrArr.const map: <readonly [Check<Meta>, ...Check<Meta>[]], SchemaAST.Check<any>>(self: readonly [Check<Meta>, ...Check<Meta>[]], f: (a: Check<Meta>, i: number) => SchemaAST.Check<any>) => [SchemaAST.Check<any>, ...SchemaAST.Check<any>[]] (+1 overload)map(check: Check<Meta>(parameter) check: {
_tag: "FilterGroup";
annotations: Schema.Annotations.Filter | undefined;
checks: readonly [Check<M>, ...Array<Check<M>>];
}
check.FilterGroup<Meta>.checks: readonly [Check<M>, ...Array<Check<M>>](property) FilterGroup<Meta>.checks: {
0: Check<Meta>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<Check<Meta>>>): Array<Check<Meta>>; (...items: Array<Check<Meta> | ConcatArray<Check<Meta>>>): Array<Check<Meta>> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<Check<Meta>>;
indexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Check<Meta>, fromIndex?: number) => number;
every: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisAr…;
some: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): Ar…;
reduce: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
reduceRight: { (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex: number, array: ReadonlyArray<Check<Meta>>) => Check<Meta>): Check<Meta>; (callbackfn: (previousValue: Check<Meta>, currentValue: Check<Meta>, currentIndex…;
find: { (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any): C…;
findIndex: (predicate: (value: Check<Meta>, index: number, obj: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, Check<Meta>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Check<Meta>>;
includes: (searchElement: Check<Meta>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Check<Meta>, index: number, array: Array<Check<Meta>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Check<Meta> | undefined;
findLast: { (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any…;
findLastIndex: (predicate: (value: Check<Meta>, index: number, array: ReadonlyArray<Check<Meta>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Check<Meta>>;
toSorted: (compareFn?: ((a: Check<Meta>, b: Check<Meta>) => number) | undefined) => Array<Check<Meta>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Check<Meta>>): Array<Check<Meta>>; (start: number, deleteCount?: number): Array<Check<Meta>> };
with: (index: number, value: Check<Meta>) => Array<Check<Meta>>;
}
checks, function (local function) toSchemaCheck(check: Check<Meta>): SchemaAST.Check<any>toSchemaCheck), check: Check<Meta>(parameter) check: {
_tag: "FilterGroup";
annotations: Schema.Annotations.Filter | undefined;
checks: readonly [Check<M>, ...Array<Check<M>>];
}
check.FilterGroup<M>.annotations?: Schema.Annotations.Filter | undefinedannotations)
}
}
}
function function (local function) toSchemaFilter(filter: Filter<Meta>): SchemaAST.Check<any>toSchemaFilter(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter: interface Filter<M>A single validation constraint with typed metadata describing the check
(e.g. { _tag: "isMinLength", minLength: 3 }).
Filter<type Meta = {
readonly _tag: "isDateValid";
} | {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
} | {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
} | {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
} | {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
} | {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
} | ... 40 more ... | {
...;
}
Meta>): import SchemaASTSchemaAST.type Check<T> =
| SchemaAST.Filter<T>
| SchemaAST.FilterGroup<T>
Check<any> {
const const a:
| Schema.Annotations.Filter
| undefined
a = filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<M>.annotations?: Schema.Annotations.Filter | undefinedannotations
switch (filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: Metameta._tag: "isDateValid" | "isGreaterThanDate" | "isGreaterThanOrEqualToDate" | "isLessThanDate" | "isLessThanOrEqualToDate" | "isBetweenDate" | "isMinSize" | "isMaxSize" | "isSizeBetween" | "isStringFinite" | "isStringBigInt" | "isStringSymbol" | "isMinLength" | "isMaxLength" | "isPattern" | "isLengthBetween" | "isTrimmed" | "isUUID" | "isGUID" | "isULID" | "isBase64" | "isBase64Url" | "isStartsWith" | "isEndsWith" | "isIncludes" | "isUppercased" | "isLowercased" | "isCapitalized" | "isUncapitalized" | "isInt" | "isFinite" | "isMultipleOf" | ... 14 more ... | "isPropertyNames"_tag) {
// String Meta
case "isStringFinite":
return import SchemaSchema.const isStringFinite: (
annotations?: Annotations.Filter
) => SchemaAST.Filter<string>
Validates that a string represents a finite number.
Details
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that matches
strings representing finite numbers.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the number string pattern.
isStringFinite(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isStringBigInt":
return import SchemaSchema.const isStringBigInt: (
annotations?: Annotations.Filter
) => SchemaAST.Filter<string>
Validates that a string is a signed base-10 integer literal for Effect's
BigInt string encoding.
Details
The check uses the pattern ^-?\d+$. It does not accept leading +, decimal
points, exponent notation, separators, or non-decimal inputs such as
hexadecimal strings.
JSON Schema:
This check corresponds to a pattern constraint with the same signed
base-10 integer pattern.
isStringBigInt(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isStringSymbol":
return import SchemaSchema.const isStringSymbol: (
annotations?: Annotations.Filter
) => SchemaAST.Filter<string>
Validates that a string has the Symbol(description) format used by Effect's
symbol string encoding.
Details
The check uses the pattern ^Symbol\((.*)\)$. It is not a general test for
whether a string can be passed to JavaScript's Symbol() function.
isStringSymbol(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isMinLength":
return import SchemaSchema.function isMinLength(
minLength: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly length: number
}>
Validates that a value has at least the specified length. Works with strings
and arrays.
Details
JSON Schema:
This check corresponds to the minLength constraint for strings or the
minItems constraint for arrays in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a minLength
constraint to ensure generated strings or arrays have at least the required
length.
Example (Checking minimum length)
import { Schema } from "effect"
const NonEmptyStringSchema = Schema.String.check(Schema.isMinLength(1))
const NonEmptyArraySchema = Schema.Array(Schema.Number).check(Schema.isMinLength(1))
isMinLength(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinLength";
readonly minLength: number;
}
meta.minLength: numberminLength, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isMaxLength":
return import SchemaSchema.function isMaxLength(
maxLength: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly length: number
}>
Validates that a value has at most the specified length. Works with strings
and arrays.
Details
JSON Schema:
This check corresponds to the maxLength constraint for strings or the
maxItems constraint for arrays in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a maxLength
constraint to ensure generated strings or arrays have at most the required
length.
isMaxLength(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxLength";
readonly maxLength: number;
}
meta.maxLength: numbermaxLength, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLengthBetween":
return import SchemaSchema.function isLengthBetween(
minimum: number,
maximum: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly length: number
}>
Validates that a value's length is within the specified range. Works with
strings and arrays.
Details
JSON Schema:
This check corresponds to minLength/maxLength constraints for strings
or minItems/maxItems constraints for arrays in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies minLength and
maxLength constraints to ensure generated strings or arrays have a length
within the specified range.
isLengthBetween(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum, filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isPattern":
return import SchemaSchema.const isPattern: (
regExp: globalThis.RegExp,
annotations?: Annotations.Filter
) => SchemaAST.Filter<string>
Validates that a string matches the specified regular expression pattern.
Details
JSON Schema:
This check corresponds to the pattern constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the specified RegExp pattern.
isPattern(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isPattern";
readonly regExp: globalThis.RegExp;
}
meta.regExp: RegExpregExp, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isTrimmed":
return import SchemaSchema.function isTrimmed(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string has no leading or trailing whitespace.
Details
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that
matches strings without leading or trailing whitespace.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the trimmed pattern.
isTrimmed(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isUUID":
return import SchemaSchema.function isUUID(
version?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is a strict Universally Unique Identifier (UUID).
When to use
Use when you need UUID semantics, including version and RFC variant bits,
rather than only the dashed hexadecimal shape.
Details
Without a version argument, this accepts UUID versions 1 through 8, the nil
UUID (00000000-0000-0000-0000-000000000000), and the max UUID
(ffffffff-ffff-ffff-ffff-ffffffffffff). With a version argument, this
accepts only UUIDs with that version and RFC variant bits; nil and max UUIDs
are not versioned UUIDs and do not match version-specific checks.
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that matches
UUID format, and includes a format: "uuid" annotation.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the UUID pattern.
isUUID(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isUUID";
readonly regExp: globalThis.RegExp;
readonly version: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | undefined;
}
meta.version: | 2
| 1
| 3
| 6
| 4
| 5
| 7
| 8
| undefined
version, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGUID":
return import SchemaSchema.function isGUID(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string has the GUID / UUID textual shape.
When to use
Use when you need to accept dashed hexadecimal identifiers without enforcing
UUID version or variant bits.
Details
This check accepts strings in the 8-4-4-4-12 hexadecimal form. JSON Schema
output includes the corresponding pattern constraint and intentionally does
not include format: "uuid" because GUID validation is looser than UUID
validation.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the GUID pattern.
isGUID(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isULID":
return import SchemaSchema.function isULID(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is a valid ULID (Universally Unique Lexicographically
Sortable Identifier).
Details
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that matches
the ULID format.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the ULID pattern.
isULID(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isBase64":
return import SchemaSchema.function isBase64(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is valid Base64 encoded data.
Details
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that matches
Base64 format.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the Base64 pattern.
isBase64(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isBase64Url":
return import SchemaSchema.function isBase64Url(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is valid Base64URL encoded data (Base64 with URL-safe
characters).
Details
JSON Schema:
This check corresponds to a pattern constraint in JSON Schema that matches
Base64URL format.
Arbitrary:
When generating test data with fast-check, this applies a patterns
constraint to ensure generated strings match the Base64URL pattern.
isBase64Url(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isStartsWith":
return import SchemaSchema.function isStartsWith(
startsWith: string,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates at runtime that a string starts with the specified literal prefix.
Details
Notes:
The JSON Schema and arbitrary metadata are built from ^${startsWith} without
escaping regexp metacharacters. If the prefix contains regexp syntax, generated
patterns may not be equivalent to the runtime startsWith check.
isStartsWith(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isStartsWith";
readonly startsWith: string;
readonly regExp: globalThis.RegExp;
}
meta.startsWith: stringstartsWith, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isEndsWith":
return import SchemaSchema.function isEndsWith(
endsWith: string,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates at runtime that a string ends with the specified literal suffix.
Details
Notes:
The JSON Schema and arbitrary metadata are built from ${endsWith}$ without
escaping regexp metacharacters. If the suffix contains regexp syntax, generated
patterns may not be equivalent to the runtime endsWith check.
isEndsWith(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isEndsWith";
readonly endsWith: string;
readonly regExp: globalThis.RegExp;
}
meta.endsWith: stringendsWith, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isIncludes":
return import SchemaSchema.function isIncludes(
includes: string,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates at runtime that a string contains the specified literal substring.
Details
Notes:
The JSON Schema and arbitrary metadata use the substring as a raw regexp
pattern. If the substring contains regexp syntax, generated patterns may not be
equivalent to the runtime includes check.
isIncludes(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isIncludes";
readonly includes: string;
readonly regExp: globalThis.RegExp;
}
meta.includes: stringincludes, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isUppercased":
return import SchemaSchema.function isUppercased(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is unchanged by JavaScript's toUpperCase().
Details
This accepts empty strings and characters that do not have lowercase forms,
such as digits, punctuation, and whitespace. It rejects strings that would
change when uppercased.
isUppercased(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLowercased":
return import SchemaSchema.function isLowercased(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that a string is unchanged by JavaScript's toLowerCase().
Details
This accepts empty strings and characters that do not have uppercase forms,
such as digits, punctuation, and whitespace. It rejects strings that would
change when lowercased.
isLowercased(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isCapitalized":
return import SchemaSchema.function isCapitalized(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that the first character of a string is unchanged by
toUpperCase().
Details
Empty strings pass. Strings whose first character has no lowercase form, such
as a digit, punctuation mark, or whitespace, also pass.
isCapitalized(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isUncapitalized":
return import SchemaSchema.function isUncapitalized(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<string>
Validates that the first character of a string is unchanged by
toLowerCase().
Details
Empty strings pass. Strings whose first character has no uppercase form, such
as a digit, punctuation mark, or whitespace, also pass.
isUncapitalized(const a:
| Schema.Annotations.Filter
| undefined
a)
// Number Meta
case "isFinite":
return import SchemaSchema.function isFinite(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<number>
Validates that a number is finite (not Infinity, -Infinity, or NaN).
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, but ensures the
number is valid and finite.
Arbitrary:
When generating test data with fast-check, this applies noNaN: true and
noInfinity: true constraints to ensure generated numbers are finite.
isFinite(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isInt":
return import SchemaSchema.function isInt(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<number>
Validates that a number is a safe integer (within the safe integer range
that can be exactly represented in JavaScript).
Details
JSON Schema:
This check corresponds to the type: "integer" constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies an integer: true
constraint to ensure generated numbers are integers.
isInt(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isMultipleOf":
return import SchemaSchema.const isMultipleOf: (
divisor: number,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is a multiple of the specified divisor.
Details
JSON Schema:
This check corresponds to the multipleOf constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies constraints to ensure
generated numbers are multiples of the specified divisor.
isMultipleOf(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMultipleOf";
readonly divisor: number;
}
meta.divisor: numberdivisor, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGreaterThan":
return import SchemaSchema.const isGreaterThan: (
exclusiveMinimum: number,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is greater than the specified value (exclusive).
Details
JSON Schema:
This check corresponds to the exclusiveMinimum constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies an
exclusiveMinimum constraint to ensure generated numbers are greater than
the specified value.
isGreaterThan(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThan";
readonly exclusiveMinimum: number;
}
meta.exclusiveMinimum: numberexclusiveMinimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGreaterThanOrEqualTo":
return import SchemaSchema.const isGreaterThanOrEqualTo: (
minimum: number,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is greater than or equal to the specified value
(inclusive).
Details
JSON Schema:
This check corresponds to the minimum constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a minimum constraint
to ensure generated numbers are greater than or equal to the specified value.
isGreaterThanOrEqualTo(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanOrEqualTo";
readonly minimum: number;
}
meta.minimum: numberminimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThan":
return import SchemaSchema.const isLessThan: (
exclusiveMaximum: number,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is less than the specified value (exclusive).
Details
JSON Schema:
This check corresponds to the exclusiveMaximum constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies an
exclusiveMaximum constraint to ensure generated numbers are less than the
specified value.
isLessThan(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThan";
readonly exclusiveMaximum: number;
}
meta.exclusiveMaximum: numberexclusiveMaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThanOrEqualTo":
return import SchemaSchema.const isLessThanOrEqualTo: (
maximum: number,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is less than or equal to the specified value
(inclusive).
Details
JSON Schema:
This check corresponds to the maximum constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a maximum constraint
to ensure generated numbers are less than or equal to the specified value.
isLessThanOrEqualTo(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanOrEqualTo";
readonly maximum: number;
}
meta.maximum: numbermaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isBetween":
return import SchemaSchema.const isBetween: (
options: {
readonly minimum: number
readonly maximum: number
readonly exclusiveMinimum?:
| boolean
| undefined
readonly exclusiveMaximum?:
| boolean
| undefined
},
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<number>
Validates that a number is within a specified range. The range boundaries can
be inclusive or exclusive based on the provided options.
Details
JSON Schema:
This check corresponds to minimum/maximum or exclusiveMinimum/exclusiveMaximum
constraints in JSON Schema, depending on the options provided.
Arbitrary:
When generating test data with fast-check, this applies minimum and
maximum constraints with optional exclusiveMinimum and
exclusiveMaximum flags to ensure generated numbers fall within the
specified range.
isBetween(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetween";
readonly minimum: number;
readonly maximum: number;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta, const a:
| Schema.Annotations.Filter
| undefined
a)
// BigInt Meta
case "isGreaterThanBigInt":
return import SchemaSchema.const isGreaterThanBigInt: (
exclusiveMinimum: bigint,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<bigint>
Validates that a BigInt is greater than the specified value (exclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a min constraint of
exclusiveMinimum + 1n to ensure generated BigInts are greater than the
specified value.
isGreaterThanBigInt(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanBigInt";
readonly exclusiveMinimum: bigint;
}
meta.exclusiveMinimum: bigintexclusiveMinimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGreaterThanOrEqualToBigInt":
return import SchemaSchema.const isGreaterThanOrEqualToBigInt: (
minimum: bigint,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<bigint>
Validates that a BigInt is greater than or equal to the specified value
(inclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a min constraint
to ensure generated BigInt values are greater than or equal to the specified
value.
isGreaterThanOrEqualToBigInt(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanOrEqualToBigInt";
readonly minimum: bigint;
}
meta.minimum: bigintminimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThanBigInt":
return import SchemaSchema.const isLessThanBigInt: (
exclusiveMaximum: bigint,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<bigint>
Validates that a BigInt is less than the specified value (exclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a max constraint of
exclusiveMaximum - 1n to ensure generated BigInts are less than the
specified value.
isLessThanBigInt(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanBigInt";
readonly exclusiveMaximum: bigint;
}
meta.exclusiveMaximum: bigintexclusiveMaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThanOrEqualToBigInt":
return import SchemaSchema.const isLessThanOrEqualToBigInt: (
maximum: bigint,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<bigint>
Validates that a BigInt is less than or equal to the specified value
(inclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a max constraint
to ensure generated BigInt values are less than or equal to the specified
value.
isLessThanOrEqualToBigInt(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanOrEqualToBigInt";
readonly maximum: bigint;
}
meta.maximum: bigintmaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isBetweenBigInt":
return import SchemaSchema.const isBetweenBigInt: (
options: {
readonly minimum: bigint
readonly maximum: bigint
readonly exclusiveMinimum?:
| boolean
| undefined
readonly exclusiveMaximum?:
| boolean
| undefined
},
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<bigint>
Validates that a BigInt is within a specified range. The range boundaries can
be inclusive or exclusive based on the provided options.
Details
Arbitrary:
When generating test data with fast-check, this applies min and max
constraints to ensure generated BigInt values fall within the specified
range.
isBetweenBigInt(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenBigInt";
readonly minimum: bigint;
readonly maximum: bigint;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta, const a:
| Schema.Annotations.Filter
| undefined
a)
// Object Meta
case "isMinProperties":
return import SchemaSchema.function isMinProperties(
minProperties: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<object>
Validates that an object contains at least the specified number of
properties. This includes both string and symbol keys when counting
properties.
Details
JSON Schema:
This check corresponds to the minProperties constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a node-local
minLength constraint. Object generators interpret it as the final number
of own properties.
isMinProperties(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinProperties";
readonly minProperties: number;
}
meta.minProperties: numberminProperties, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isMaxProperties":
return import SchemaSchema.function isMaxProperties(
maxProperties: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<object>
Validates that an object contains at most the specified number of properties.
This includes both string and symbol keys when counting properties.
Details
JSON Schema:
This check corresponds to the maxProperties constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a node-local
maxLength constraint. Object generators interpret it as the final number
of own properties.
isMaxProperties(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxProperties";
readonly maxProperties: number;
}
meta.maxProperties: numbermaxProperties, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isPropertiesLengthBetween":
return import SchemaSchema.function isPropertiesLengthBetween(
minimum: number,
maximum: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<object>
Validates that an object contains between minimum and maximum properties (inclusive).
This includes both string and symbol keys when counting properties.
Details
JSON Schema:
This check corresponds to minProperties and maxProperties
constraints in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies node-local
minLength and maxLength constraints. Object generators interpret them as
the final number of own properties.
isPropertiesLengthBetween(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isPropertiesLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum, filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isPropertiesLengthBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isPropertyNames":
return import SchemaSchema.function isPropertyNames(
keySchema: Constraint,
annotations?: Annotations.Filter
): SchemaAST.Filter<object>
Validates that every own property key of an object satisfies the encoded side
of the provided key schema.
Details
This check uses Reflect.ownKeys, so symbol keys are validated in addition to
string property names.
JSON Schema:
For string property names, this corresponds to the propertyNames constraint
in JSON Schema.
isPropertyNames(function (local function) recur(r: Representation): Schema.Toprecur(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
...;
}
meta.propertyNames: RepresentationpropertyNames) as import SchemaSchema.Record.interface Record.KeyConstraint for schemas that can be used as record keys.
Details
The key schema must decode and encode property keys (string, number, or
symbol) so it can describe object property names.
Key, const a:
| Schema.Annotations.Filter
| undefined
a)
// Arrays Meta
case "isUnique":
return import SchemaSchema.function isUnique<unknown>(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<readonly unknown[]>
Validates that all items in an array are unique according to Effect equality.
Details
JSON Schema:
This check corresponds to the uniqueItems: true constraint in JSON Schema.
Arbitrary:
When generating test data with fast-check, this applies a node-local
unique: true constraint. Array generators translate it to fast-check
uniqueArray using Effect equality.
isUnique(const a:
| Schema.Annotations.Filter
| undefined
a)
// Date Meta
case "isDateValid":
return import SchemaSchema.function isDateValid(
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<Date>
Validates that a Date object represents a valid date (not an invalid date
like new Date("invalid")).
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as JSON Schema
validates date strings, not Date objects.
Arbitrary:
When generating test data with fast-check, this applies a valid: true
constraint to ensure generated Date objects are valid.
isDateValid(const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGreaterThanDate":
return import SchemaSchema.const isGreaterThanDate: (
exclusiveMinimum: Date,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<Date>
Validates that a Date is greater than the specified value (exclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a min constraint of
one millisecond after the specified value to ensure generated Date objects are
greater than it.
isGreaterThanDate(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanDate";
readonly exclusiveMinimum: globalThis.Date;
}
meta.exclusiveMinimum: DateexclusiveMinimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isGreaterThanOrEqualToDate":
return import SchemaSchema.const isGreaterThanOrEqualToDate: (
minimum: Date,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<Date>
Validates that a Date is greater than or equal to the specified date
(inclusive).
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as JSON Schema
validates date strings, not Date objects.
Arbitrary:
When generating test data with fast-check, this applies a min constraint
to ensure generated Date objects are greater than or equal to the specified
date.
isGreaterThanOrEqualToDate(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isGreaterThanOrEqualToDate";
readonly minimum: globalThis.Date;
}
meta.minimum: Dateminimum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThanDate":
return import SchemaSchema.const isLessThanDate: (
exclusiveMaximum: Date,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<Date>
Validates that a Date is less than the specified value (exclusive).
Details
Arbitrary:
When generating test data with fast-check, this applies a max constraint of
one millisecond before the specified value to ensure generated Date objects
are less than it.
isLessThanDate(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanDate";
readonly exclusiveMaximum: globalThis.Date;
}
meta.exclusiveMaximum: DateexclusiveMaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isLessThanOrEqualToDate":
return import SchemaSchema.const isLessThanOrEqualToDate: (
maximum: Date,
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<Date>
Validates that a Date is less than or equal to the specified date
(inclusive).
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as JSON Schema
validates date strings, not Date objects.
Arbitrary:
When generating test data with fast-check, this applies a max constraint
to ensure generated Date objects are less than or equal to the specified
date.
isLessThanOrEqualToDate(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isLessThanOrEqualToDate";
readonly maximum: globalThis.Date;
}
meta.maximum: Datemaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isBetweenDate":
return import SchemaSchema.const isBetweenDate: (
options: {
readonly minimum: Date
readonly maximum: Date
readonly exclusiveMinimum?:
| boolean
| undefined
readonly exclusiveMaximum?:
| boolean
| undefined
},
annotations?: Schema.Annotations.Filter
) => SchemaAST.Filter<Date>
Validates that a Date is within a specified range. The range boundaries can
be inclusive or exclusive based on the provided options.
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as JSON Schema
validates date strings, not Date objects.
Arbitrary:
When generating test data with fast-check, this applies min and max
constraints to ensure generated Date objects fall within the specified range,
shifting exclusive bounds by one millisecond.
isBetweenDate(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isBetweenDate";
readonly minimum: globalThis.Date;
readonly maximum: globalThis.Date;
readonly exclusiveMinimum?: boolean | undefined;
readonly exclusiveMaximum?: boolean | undefined;
}
meta, const a:
| Schema.Annotations.Filter
| undefined
a)
// Size Meta
case "isMinSize":
return import SchemaSchema.function isMinSize(
minSize: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly size: number
}>
Validates that a value has at least the specified size. Works with values
that have a size property, such as Set or Map.
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as it applies to
values with a size property rather than standard JSON Schema types.
Arbitrary:
When generating test data with fast-check, this applies a node-local
minLength constraint. Generators for values with a final .size, such as
sets and maps, interpret it as final cardinality.
isMinSize(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMinSize";
readonly minSize: number;
}
meta.minSize: numberminSize, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isMaxSize":
return import SchemaSchema.function isMaxSize(
maxSize: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly size: number
}>
Validates that a value has at most the specified size. Works with values
that have a size property, such as Set or Map.
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as it applies to
values with a size property rather than standard JSON Schema types.
Arbitrary:
When generating test data with fast-check, this applies a node-local
maxLength constraint. Generators for values with a final .size, such as
sets and maps, interpret it as final cardinality.
isMaxSize(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isMaxSize";
readonly maxSize: number;
}
meta.maxSize: numbermaxSize, const a:
| Schema.Annotations.Filter
| undefined
a)
case "isSizeBetween":
return import SchemaSchema.function isSizeBetween(
minimum: number,
maximum: number,
annotations?: Schema.Annotations.Filter
): SchemaAST.Filter<{
readonly size: number
}>
Validates that a value's size is within the specified range. Works with
values that have a size property, such as Set or Map.
Details
JSON Schema:
This check does not have a direct JSON Schema equivalent, as it applies to
values with a size property rather than standard JSON Schema types.
Arbitrary:
When generating test data with fast-check, this applies node-local
minLength and maxLength constraints. Generators for values with a final
.size, such as sets and maps, interpret them as final cardinality.
isSizeBetween(filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isSizeBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.minimum: numberminimum, filter: Filter<Meta>(parameter) filter: {
_tag: "Filter";
annotations: Schema.Annotations.Filter | undefined;
meta: M;
}
filter.Filter<Meta>.meta: {
readonly _tag: "isSizeBetween";
readonly minimum: number;
readonly maximum: number;
}
meta.maximum: numbermaximum, const a:
| Schema.Annotations.Filter
| undefined
a)
}
}
}