SchemaAST
Represents Effect schemas as runtime trees.
Every Schema has an AST made from nodes for declarations, primitives,
literals, arrays, objects, unions, suspended schemas, checks, annotations,
encoding links, and parsing context. Most users work with the higher-level
Schema module. Use SchemaAST when you need to inspect schema nodes, build
ASTs programmatically, change encoded or decoded views, collect issues, or
run low-level schema checks.
Annotations
Returns all annotations from the AST node.
Details
If the node has Checks, returns annotations from the last check
(which is where user-supplied annotations end up after .pipe(Schema.annotations(...))).
Otherwise returns the node's annotations directly.
See
Signature
declare const resolve: (ast: AST) => Schema.Annotations.Annotations | undefinedExample
(Reading annotations)
import { Schema, SchemaAST } from "effect"
const schema = Schema.String.annotate({ title: "Name" })const annotations = SchemaAST.resolve(schema.ast)annotations?.title // => "Name"Returns a single annotation value by key from the AST node.
Details
Like resolve, reads from the last check's annotations when checks
are present. Returns undefined if the key is not found.
See
Signature
declare const resolveAt: <A>(key: string) => (ast: AST) => A | undefinedresolveDescription
Returns the description annotation from the AST node, if set.
See
Signature
declare const resolveDescription: (ast: AST) => string | undefinedresolveIdentifier
Returns the identifier annotation from the AST node, if set.
Details
The identifier is typically set by Schema.annotations({ identifier: "..." })
and is used for error messages and schema identification.
See
Signature
declare const resolveIdentifier: (ast: AST) => string | undefinedresolveTitle
Returns the title annotation from the AST node, if set.
See
Signature
declare const resolveTitle: (ast: AST) => string | undefinedConstructors
Provides the singleton Any AST instance.
When to use
Use when you need the singleton AST node for the TypeScript any type and
intentionally want parsing to accept every input value.
See
- unknown for the sibling AST singleton that also accepts every value while preserving the safer
unknowntype
Signature
declare const any: AnyConstructs a Any.
Signature
declare const Any: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => AnyConstructs a Arrays.
Signature
declare const Arrays: (isMutable: boolean, elements: readonly Array<AST>, rest: readonly Array<AST>, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context, encodingChecks?: readonly [Check<any>, Check<any>]) => ArraysProvides the singleton BigInt AST instance.
When to use
Use to reuse the canonical BigInt AST node when constructing, inspecting,
or transforming schemas at the AST level.
See
Signature
declare const bigInt: BigIntConstructs a BigInt.
Signature
declare const BigInt: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => BigIntProvides the singleton Boolean AST instance.
When to use
Use to reuse the standard AST node that accepts either true or false when
constructing schema ASTs directly.
See
Signature
declare const boolean: BooleanConstructs a Boolean.
Signature
declare const Boolean: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => BooleanConstructs a Context.
Signature
declare const Context: (isOptional: boolean, isMutable: boolean, constructorDefault?: Link, annotations?: Key<unknown>) => ContextDeclaration
Constructs a Declaration.
Signature
declare const Declaration: (typeParameters: readonly Array<AST>, run: DeclarationRun, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context, encodingChecks?: readonly [Check<any>, Check<any>], encodingRun?: DeclarationRun) => DeclarationConstructs a Enum. Numeric values must be finite.
Signature
declare const Enum: (enums: readonly Array<readonly [string, string | number]>, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => EnumConstructs a Filter.
Signature
declare const Filter: <E>(run: (input: E, self: AST, options: ParseOptions) => Issue | undefined, annotations?: Filter, aborted?: boolean) => Filter<E>FilterGroup
Constructs a FilterGroup.
Signature
declare const FilterGroup: <E>(checks: readonly [Check<E>, Check<E>], annotations?: Filter) => FilterGroup<E>IndexSignature
Constructs a IndexSignature.
Signature
declare const IndexSignature: (parameter: AST, type: AST) => IndexSignatureCreates a Filter that validates strings by running RegExp.test.
When to use
Use when string validation should be represented as a schema Filter backed
by a regular expression.
Details
The filter can be used with Schema.filter or attached directly to a
String AST node through checks. The regular expression is cloned and its
lastIndex is reset before each test, so global and sticky expressions are
deterministic and the provided regular expression is not mutated. The
regular expression source is stored in annotations for serialization and
arbitrary generation.
Gotchas
Arbitrary metadata preserves both regExp.source and regExp.flags.
Implementations that cannot consume all flags may still use the source as a
generation hint because the Schema filter validates every generated value.
JSON Schema has no way to carry JavaScript regular-expression flags. The
generated pattern contains the source only, so validation can differ when
the RegExp uses flags or relies on JavaScript's non-Unicode behavior.
See
Signature
declare function isPattern(regExp: RegExp, annotations?: Filter): Filter<string>Example
(Validating an email pattern)
import { SchemaAST } from "effect"
const emailFilter = SchemaAST.isPattern(/^[^@]+@[^@]+$/)emailFilter.run("alice@example.com", SchemaAST.string, {}) // => undefinedemailFilter.run("invalid", SchemaAST.string, {})?._tag // => "InvalidValue"Constructs a Link.
Signature
declare const Link: (to: AST, transformation: Middleware<any, any, any, any, any, any> | Transformation<any, any, any, any>) => LinkConstructs a Literal.
Signature
declare const Literal: (literal: LiteralValue, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => LiteralProvides the singleton Never AST instance.
When to use
Use to reuse the canonical bottom-type AST node when constructing, comparing, or returning ASTs.
See
Signature
declare const never: NeverConstructs a Never.
Signature
declare const Never: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => NeverConstructs a Null.
Signature
declare const Null: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => NullProvides the singleton Number AST instance.
When to use
Use when you need the canonical SchemaAST node for schemas that accept any
JavaScript number value.
See
Signature
declare const number: NumberConstructs a Number.
Signature
declare const Number: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => NumberobjectKeyword
Provides the singleton ObjectKeyword AST instance.
When to use
Use to reuse the canonical AST node for the TypeScript object keyword when
building or comparing SchemaAST values directly.
See
- ObjectKeyword for the AST node class
- isObjectKeyword for narrowing an AST to an
ObjectKeywordnode
Signature
declare const objectKeyword: ObjectKeywordObjectKeyword
Constructs a ObjectKeyword.
Signature
declare const ObjectKeyword: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => ObjectKeywordConstructs a Objects.
Signature
declare const Objects: (propertySignatures: readonly Array<PropertySignature>, indexSignatures: readonly Array<IndexSignature>, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context, encodingChecks?: readonly [Check<any>, Check<any>]) => ObjectsPropertySignature
Constructs a PropertySignature.
Signature
declare const PropertySignature: (name: PropertyKey, type: AST) => PropertySignatureProvides the singleton String AST instance.
When to use
Use as the shared SchemaAST node for unconstrained JavaScript strings.
See
Signature
declare const string: StringConstructs a String.
Signature
declare const String: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => StringConstructs a Suspend.
Signature
declare const Suspend: (thunk: () => AST, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => SuspendProvides the singleton Symbol AST instance.
When to use
Use to reuse the singleton AST node for schemas that match any JavaScript symbol value.
Gotchas
String-based codecs can encode only symbols registered with Symbol.for,
because the implementation uses Symbol.keyFor.
See
- UniqueSymbol for an AST node that matches one specific symbol
Signature
declare const symbol: SymbolConstructs a Symbol.
Signature
declare const Symbol: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => SymbolTemplateLiteral
Constructs a TemplateLiteral.
Gotchas
Throws if a part contains an encoding, including inside unions or nested template literals. Parts must describe their values without transformations.
Signature
declare const TemplateLiteral: (parts: readonly Array<AST>, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => TemplateLiteralConstructs a Undefined.
Signature
declare const Undefined: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => UndefinedConstructs a Union.
Signature
declare const Union: <A extends AST = AST>(types: readonly Array<A>, options?: UnionOptions, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context, encodingChecks?: readonly [Check<any>, Check<any>]) => Union<A>UniqueSymbol
Constructs a UniqueSymbol.
Signature
declare const UniqueSymbol: (symbol: symbol, annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => UniqueSymbolProvides the singleton Unknown AST instance.
When to use
Use when you need the reusable AST singleton for a schema node that accepts every value while keeping parsed values opaque.
See
- any for the singleton that accepts every value as
any
Signature
declare const unknown: UnknownConstructs a Unknown.
Signature
declare const Unknown: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => UnknownConstructs a Void.
Signature
declare const Void: (annotations?: Annotations, checks?: readonly [Check<any>, Check<any>], encoding?: readonly [Link, Link], context?: Context) => VoidGuards
When to use
Use when you need to inspect a schema AST and handle the Any node
variant specifically.
See
- isUnknown for the guard for the
Unknownnode, whose parsed result is typed asunknownrather thanany
Signature
declare const isAny: (ast: AST) => ast is AnyWhen to use
Use to recognize array-like AST nodes before reading their element, rest, or mutability metadata.
See
- Arrays for the AST node type narrowed by this guard
Signature
declare const isArrays: (ast: AST) => ast is ArraysReturns true if the value is an AST node (any variant).
Details
Uses the internal TypeId brand to distinguish AST nodes from arbitrary
objects.
See
Signature
declare function isAST(u: unknown): u is ASTWhen to use
Use to identify bigint AST nodes while inspecting or transforming schema ASTs.
See
Signature
declare const isBigInt: (ast: AST) => ast is BigIntWhen to use
Use to identify the Boolean AST variant while inspecting, traversing, or
transforming schema definitions.
See
Signature
declare const isBoolean: (ast: AST) => ast is BooleanisDeclaration
Narrows an AST to Declaration.
When to use
Use to recognize declaration AST nodes before running declaration-specific handling.
See
- Declaration for the AST node type narrowed by this guard
Signature
declare const isDeclaration: (ast: AST) => ast is DeclarationWhen to use
Use to recognize enum AST nodes before reading enum cases or running enum-specific handling.
See
- Enum for the AST node type narrowed by this guard
Signature
declare const isEnum: (ast: AST) => ast is EnumWhen to use
Use to recognize exact string, number, boolean, or bigint literal AST nodes.
See
- Literal for the AST node type narrowed by this guard
- LiteralValue for the values stored by literal nodes
Signature
declare const isLiteral: (ast: AST) => ast is LiteralWhen to use
Use to detect the AST node for a schema that can never match before handling other schema variants.
See
Signature
declare const isNever: (ast: AST) => ast is NeverWhen to use
Use to recognize an AST node that represents exactly the null literal when
inspecting, traversing, or transforming schema ASTs.
See
Signature
declare const isNull: (ast: AST) => ast is NullWhen to use
Use to detect Number AST nodes while inspecting, traversing, or transforming
schema ASTs.
Signature
declare const isNumber: (ast: AST) => ast is NumberisObjectKeyword
Narrows an AST to ObjectKeyword.
When to use
Use to identify the AST node for the TypeScript object keyword when
inspecting or transforming a Schema AST.
See
- ObjectKeyword for the AST node matched by this guard
- objectKeyword for the singleton
ObjectKeywordAST instance - isObjects for struct and record AST nodes
Signature
declare const isObjectKeyword: (ast: AST) => ast is ObjectKeywordSignature
declare const isObjects: (ast: AST) => ast is ObjectsWhen to use
Use to detect schema AST nodes that match any string value while inspecting or transforming a Schema AST.
See
Signature
declare const isString: (ast: AST) => ast is StringSignature
declare const isSuspend: (ast: AST) => ast is SuspendWhen to use
Use to narrow an AST node before handling the Symbol variant for schemas
that accept any JavaScript symbol value.
See
- isUniqueSymbol for the sibling guard that narrows the
UniqueSymbolvariant for one exact symbol value
Signature
declare const isSymbol: (ast: AST) => ast is SymbolisTemplateLiteral
Narrows an AST to TemplateLiteral.
Signature
declare const isTemplateLiteral: (ast: AST) => ast is TemplateLiteralisUndefined
When to use
Use to identify AST nodes that represent exactly the JavaScript undefined
value.
See
- isVoid for narrowing AST nodes that represent TypeScript
voidinstead of exactundefined
Signature
declare const isUndefined: (ast: AST) => ast is UndefinedSignature
declare const isUnion: (ast: AST) => ast is Union<AST>isUniqueSymbol
Narrows an AST to UniqueSymbol.
Signature
declare const isUniqueSymbol: (ast: AST) => ast is UniqueSymbolWhen to use
Use when you need to inspect a schema AST and handle the Unknown node
variant specifically.
See
- isAny for the guard for the
Anynode, whose parsed result is typed asanyrather thanunknown
Signature
declare const isUnknown: (ast: AST) => ast is UnknownWhen to use
Use to identify AST nodes that represent the TypeScript void type before
handling Void-specific schema behavior.
See
- isUndefined for narrowing AST nodes that represent the literal
undefinedvalue instead of TypeScriptvoid
Signature
declare const isVoid: (ast: AST) => ast is VoidModels
Signature
interface Any extends ASTNode { readonly _tag: "Any";}AST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas, including rest elements.
Details
elements— positional element types (tuple elements). An element is optional if its context'sisOptionalfield istrue.rest— the rest/variadic element types. When non-empty, the first entry is the "spread" type (e.g....Array<string>), and subsequent entries are trailing positional elements after the spread.isMutable— whether the resulting array isreadonly(false) or mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element cannot follow an optional one, and an optional element cannot follow a rest element.
See
Signature
interface Arrays extends ASTNode { readonly _tag: "Arrays"; readonly elements: readonly Array<AST>; readonly encodingChecks: readonly [Check<any>, Check<any>] | undefined; readonly isMutable: boolean; readonly rest: readonly Array<AST>;}Example
(Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])const ast = schema.ast
if (SchemaAST.isArrays(ast)) { [ast.elements.length, ast.rest.length] // => [2, 0]}Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(isString, isObjects, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
annotations,checks,encoding, andcontextfields. - Discriminate on the
_tagfield (e.g."String","Objects","Union").
See
Signature
type AST = Declaration | Null | Undefined | Void | Never | Unknown | Any | String | Number | Boolean | BigInt | Symbol | Literal | UniqueSymbol | ObjectKeyword | Enum | TemplateLiteral | Arrays | Objects | Union | SuspendAST node matching any bigint value.
Details
When serialized to a string-based codec, bigints are converted to/from their decimal string representation.
See
Signature
interface BigInt extends ASTNode { readonly _tag: "BigInt";}Signature
interface Boolean extends ASTNode { readonly _tag: "Boolean";}A validation check — either a single Filter or a composite FilterGroup.
Details
Stored in an AST node's Checks array.
See
Signature
type Check<T> = Filter<T> | FilterGroup<T>Non-empty array of validation Check values attached to an AST node's
checks field.
Details
Checks are run after basic type matching succeeds. They represent
refinements like minLength, pattern, int, etc.
See
Signature
type Checks = readonly [Check<any>, ...Array<Check<any>>]Represents per-property metadata attached to an AST node's context field.
Details
Tracks whether a property key is optional, mutable, has a constructor
default, or carries key-level annotations. Typically set by helpers like
optionalKey and Schema.mutableKey.
isOptional— the property key may be absent from the input.isMutable— the property isreadonlywhenfalse.constructorDefault— a Link applied during construction to supply missing values.annotations— key-level annotations (e.g. description of the key itself).
See
Schema.optionalKey- isOptional
Signature
interface Context { readonly annotations: Key<unknown> | undefined; readonly constructorDefault: Link | undefined; readonly isMutable: boolean; readonly isOptional: boolean;}Declaration interface
AST node for user-defined opaque types with custom parsing logic.
When to use
Use when you need a custom schema AST node because none of the built-in nodes fit.
Details
typeParameters— inner schemas this declaration is parameterized over (e.g. the element type for a custom collection).run— factory that receivestypeParametersand returns a parser that validates or transforms raw input. TheEffectreturned by the parser must complete synchronously.
See
Signature
interface Declaration extends ASTNode { readonly _tag: "Declaration"; readonly encodingChecks: readonly [Check<any>, Check<any>] | undefined; readonly encodingRun: DeclarationRun | undefined; readonly run: DeclarationRun; readonly typeParameters: readonly Array<AST>;}A non-empty chain of Link values representing the transformation steps between a schema's decoded (type) form and its encoded (wire) form.
Details
Stored on an AST node's encoding field. When undefined, the node has no
encoding transformation (type and encoded forms are identical).
See
Signature
type Encoding = readonly [Link, ...Array<Link>]AST node representing a TypeScript enum.
Details
Holds enums as an array of [name, value] pairs where values are
string | number. Parsing succeeds when the input matches any enum value.
See
Signature
interface Enum extends ASTNode { readonly _tag: "Enum"; readonly enums: readonly Array<readonly [string, string | number]>;}Represents a single validation check attached to an AST node.
Details
run— the validation function. Returnsundefinedon success, or anIssueon failure.annotations— optional filter-level annotations (expected message, representation, arbitrary constraint hints).aborted— whentrue, parsing stops immediately after this filter fails (no further checks run).
Use .annotate() to add metadata and .abort() to mark as aborting.
Combine with another check via .and() to form a FilterGroup.
See
Signature
interface Filter<in E> extends Pipeable { readonly _tag: "Filter"; readonly aborted: boolean; readonly annotations: Filter | undefined; readonly run: (input: E, self: AST, options: ParseOptions) => Issue | undefined; abort(): Filter<E>; and(other: Check<E>, annotations?: Filter): FilterGroup<E>; annotate(annotations: Filter): Filter<E>;}FilterGroup interface
Represents a composite validation check grouping multiple Check values.
Details
Created by calling .and() on a Filter or another FilterGroup.
All inner checks are run; failures from aborted filters still stop
evaluation.
See
Signature
interface FilterGroup<in E> extends Pipeable { readonly _tag: "FilterGroup"; readonly annotations: Filter | undefined; readonly checks: readonly [Check<E>, Check<E>]; and(other: Check<E>, annotations?: Filter): FilterGroup<E>; annotate(annotations: Filter): FilterGroup<E>;}IndexSignature interface
Represents an index signature entry within an Objects node.
When to use
Use when constructing or inspecting object AST entries for record-like keys and values.
Details
parameter— the key type AST (e.g. String forstringkeys, TemplateLiteral for patterned keys).type— the value type SchemaAST.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
See
Signature
interface IndexSignature { readonly parameter: IndexSignatureParameter; readonly type: AST;}Represents a single step in an Encoding chain.
Details
A link pairs a target AST with a Transformation or Middleware
that converts values between the current node and the target.
to— the AST node on the other side of this transformation step.transformation— the bidirectional conversion logic (decode/encode).
Links are composed into a non-empty array (Encoding) attached to AST nodes that have a different encoded representation.
See
Signature
interface Link { readonly to: AST; readonly transformation: Middleware<any, any, any, any, any, any> | Transformation<any, any, any, any>;}AST node matching an exact primitive value (string, number, boolean, or bigint).
Details
Parsing succeeds only when the input is strictly equal (===) to the
stored literal, preserving the input value. Both 0 and -0 are accepted
by either zero literal, and parsing preserves the input's sign. Numeric
literals must be finite. Infinity, -Infinity, and NaN are rejected at
construction time.
See
Signature
interface Literal extends ASTNode { readonly _tag: "Literal"; readonly literal: LiteralValue;}Example
(Creating a literal AST)
import { SchemaAST } from "effect"
const ast = new SchemaAST.Literal("active")ast.literal // => "active"LiteralValue type
Signature
type LiteralValue = string | number | boolean | bigintAST node representing the never type — no value matches.
Details
Parsing always fails. Useful as a placeholder in unions or as the result of narrowing that eliminates all options.
See
Signature
interface Never extends ASTNode { readonly _tag: "Never";}AST node matching the null literal value.
Details
Parsing succeeds only when the input is exactly null.
See
Signature
interface Null extends ASTNode { readonly _tag: "Null";}AST node matching any number value (including NaN, Infinity,
-Infinity).
Details
Default JSON serialization:
- Finite numbers are serialized as JSON numbers.
Infinity,-Infinity, andNaNare serialized as JSON strings.
If the node has an isFinite or isInt check, the string fallback is
skipped since non-finite values cannot occur.
See
Signature
interface Number extends ASTNode { readonly _tag: "Number";}ObjectKeyword interface
AST node matching the TypeScript object type — accepts objects, arrays,
and functions (anything non-primitive and non-null).
See
Signature
interface ObjectKeyword extends ASTNode { readonly _tag: "ObjectKeyword";}AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather than array-like schemas.
Details
propertySignatures— named properties with their types (struct fields).indexSignatures— index signature entries (record patterns), each with aparameterAST for matching keys and atypeAST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
See
Signature
interface Objects extends ASTNode { readonly _tag: "Objects"; readonly encodingChecks: readonly [Check<any>, Check<any>] | undefined; readonly indexSignatures: readonly Array<IndexSignature>; readonly propertySignatures: readonly Array<PropertySignature>;}Example
(Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })const ast = schema.ast
if (SchemaAST.isObjects(ast)) { ast.propertySignatures.map((ps) => [ps.name, ps.type._tag]) // => [["name", "String"]]}PropertySignature interface
Represents a named property within an Objects node.
Details
Pairs a name (any PropertyKey) with a type (AST). The
property's optionality and mutability are determined by the type's
Context.
See
Signature
interface PropertySignature { readonly name: PropertyKey; readonly type: AST;}Signature
interface String extends ASTNode { readonly _tag: "String";}AST node for lazy/recursive schemas.
Details
Wraps a thunk (() => AST) that is memoized on first call. Use this to
define recursive or mutually recursive schemas without infinite loops at
construction time.
See
Signature
interface Suspend extends ASTNode { readonly _tag: "Suspend"; readonly thunk: () => AST;}Example
(Defining recursive schema ASTs)
import { Schema, SchemaAST } from "effect"
interface Category { readonly name: string readonly children: ReadonlyArray<Category>}
const Category = Schema.Struct({ name: Schema.String, children: Schema.Array(Schema.suspend((): Schema.Codec<Category> => Category))})
SchemaAST.isObjects(Category.ast) // => trueAST node matching any symbol value.
When to use
Use when you need the AST node class for schemas that match any JavaScript symbol value.
Details
When serialized to a string-based codec, symbols are converted via
Symbol.keyFor and must be registered with Symbol.for.
See
Signature
interface Symbol extends ASTNode { readonly _tag: "Symbol";}TemplateLiteral interface
AST node representing a TypeScript template literal type
(e.g. `user_${string}`).
Details
parts is an array of AST nodes; each part contributes to matching
strings at runtime.
See
Signature
interface TemplateLiteral extends ASTNode { readonly _tag: "TemplateLiteral"; readonly parts: readonly Array<AST>;}AST node matching the undefined value.
Details
Parsing succeeds only when the input is exactly undefined.
See
Signature
interface Undefined extends ASTNode { readonly _tag: "Undefined";}AST node representing a union of schemas.
Details
types— the member AST nodes.options.modeselects matching behavior."anyOf"succeeds on the first match;"oneOf"requires exactly one member to match (fails if multiple do).
During parsing, members are tried in order. An internal candidate index narrows which members to try based on the runtime type of the input and discriminant ("sentinel") fields, making large unions efficient.
See
Signature
interface Union<A extends AST = AST> extends ASTNode { readonly _tag: "Union"; readonly encodingChecks: readonly [Check<any>, Check<any>] | undefined; readonly options: UnionOptions | undefined; readonly types: readonly Array<A>;}Example
(Inspecting a union AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])const ast = schema.ast
if (SchemaAST.isUnion(ast)) { [ast.types.length, ast.options?.mode ?? "anyOf"] // => [2, "anyOf"]}UniqueSymbol interface
AST node matching a specific unique symbol value.
Details
Parsing succeeds only when the input is reference-equal to the stored
symbol.
See
Signature
interface UniqueSymbol extends ASTNode { readonly _tag: "UniqueSymbol"; readonly symbol: symbol;}AST node representing the unknown type — every value matches.
Details
Unlike Any, this is type-safe: the parsed result is typed as
unknown rather than any.
See
Signature
interface Unknown extends ASTNode { readonly _tag: "Unknown";}AST node matching TypeScript void return-value semantics.
When to use
Use when you need an AST node for a value whose result is intentionally ignored.
Details
Parsers built from this node accept any present runtime input and map it to
undefined. Public schemas built from it may still expose void as their
typed decoded and encoded representation.
See
Signature
interface Void extends ASTNode { readonly _tag: "Void";}Options
ParseOptions interface
Options that control schema parsing, validation, transformation, and output behavior.
Details
Pass to Schema.decodeUnknown, Schema.encode, and related APIs to customize
error reporting, excess property handling, check execution, and product
concurrency. Options apply throughout the parse; schema annotations do not
override them.
errors—"first"(default) stops at the first error;"all"collects every error.onExcessProperty—"ignore"(default) strips unknown object keys;"error"fails.disableChecks— skips validation checks while still applying defaults and transformations.concurrency— controls concurrent parsing of tuple elements, array elements, struct fields, and record entries using the same semantics asEffect.forEach; the default is sequential.reportInput— includes rejected input values in value-bearing schema issues.
Object property order is unspecified, including in values passed to checks. Decoding and encoding do not guarantee preservation of input key order.
Signature
interface ParseOptions { readonly concurrency?: Concurrency; readonly disableChecks?: boolean; readonly errors?: "first" | "all"; readonly onExcessProperty?: "error" | "ignore"; readonly reportInput?: boolean;}UnionOptions interface
Local matching options stored on Union nodes.
Signature
interface UnionOptions { readonly mode?: "anyOf" | "oneOf";}Other
Predicates
isOptional
Returns true if the AST node represents an optional property.
Details
Checks ast.context?.isOptional. Defaults to false when no
Context is set.
See
Schema.optionalKey- Context
Signature
declare function isOptional(ast: AST): booleanTransforming
Attaches a Transformation to the to AST, making it decode from the
from AST and encode back to it.
Details
This is the low-level primitive behind Schema.decodeTo. It appends a
Link to the to node's encoding chain.
- Returns a new AST with the same type as
to.
See
Signature
declare function decodeTo<A extends AST>(from: AST, to: A, transformation: Transformation<any, any, any, any>): ASwaps the decode and encode directions of an AST's Encoding chain.
Details
After flipping, what was decoding becomes encoding and vice versa. This is
the core operation behind Schema.encode — encoding a value is decoding
with a flipped SchemaAST.
- Memoized: same input reference → same output reference.
- Recursively walks composite nodes.
See
Signature
declare const flip: (ast: AST) => ASTReturns the encoded (wire-format) AST by flipping and then stripping encodings.
Details
Equivalent to toType(flip(ast)). This gives you the AST that describes
the shape of the serialized/encoded data.
- Memoized: same input reference → same output reference.
See
Signature
declare const toEncoded: (a: AST) => ASTExample
(Getting the encoded AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromStringconst encodedAst = SchemaAST.toEncoded(schema.ast)encodedAst._tag // => "String"Strips all encoding transformations from an AST, returning the decoded (type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (Arrays, Objects, Union, Suspend).
See
Signature
declare const toType: <A extends AST>(a: A) => AExample
(Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromStringconst typeAst = SchemaAST.toType(schema.ast)typeAst._tag // => "Number"