SchemaAST.ts
SchemaAST.ts overview
Section titled “SchemaAST.ts overview”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.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”- annotations
- constants
- constructors
- guards
- models
- AST (type alias)
- Any (class)
- Arrays (class)
- Base (class)
- BigInt (class)
- Boolean (class)
- Check (type alias)
- Checks (type alias)
- Context (class)
- Declaration (class)
- Encoding (type alias)
- Enum (class)
- Filter (class)
- FilterGroup (class)
- IndexSignature (class)
- KeyValueCombiner (class)
- Link (class)
- Literal (class)
- LiteralValue (type alias)
- Never (class)
- Null (class)
- Number (class)
- ObjectKeyword (class)
- Objects (class)
- PropertySignature (class)
- String (class)
- Suspend (class)
- Symbol (class)
- TemplateLiteral (class)
- Undefined (class)
- Union (class)
- UniqueSymbol (class)
- Unknown (class)
- Void (class)
- options
- predicates
- transforming
annotations
Section titled “annotations”resolve
Section titled “resolve”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 Base.annotations directly.
Example (Reading annotations)
import { Schema, SchemaAST } from "effect"
const schema = Schema.String.annotate({ title: "Name" })const annotations = SchemaAST.resolve(schema.ast)console.log(annotations?.title) // "Name"See
resolveAtresolveIdentifierresolveTitleresolveDescription
Signature
declare const resolve: (ast: AST) => Schema.Annotations.Annotations | undefinedSince v4.0.0
resolveAt
Section titled “resolveAt”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
resolve
Signature
declare const resolveAt: <A>(key: string) => (ast: AST) => A | undefinedSince v4.0.0
resolveDescription
Section titled “resolveDescription”Returns the description annotation from the AST node, if set.
See
resolveresolveTitleresolveIdentifier
Signature
declare const resolveDescription: (ast: AST) => string | undefinedSince v4.0.0
resolveIdentifier
Section titled “resolveIdentifier”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
resolveresolveTitle
Signature
declare const resolveIdentifier: (ast: AST) => string | undefinedSince v4.0.0
resolveTitle
Section titled “resolveTitle”Returns the title annotation from the AST node, if set.
See
resolveresolveIdentifierresolveDescription
Signature
declare const resolveTitle: (ast: AST) => string | undefinedSince v4.0.0
constants
Section titled “constants”Provides the singleton Null AST instance.
When to use
Use when you need the shared AST node for exact null values while inspecting or constructing schema ASTs.
Signature
declare const null: NullSince v4.0.0
undefined
Section titled “undefined”Provides the singleton Undefined AST instance.
When to use
Use when you need the shared AST node for exact undefined values while inspecting or constructing schema ASTs.
Signature
declare const undefined: UndefinedSince v4.0.0
constructors
Section titled “constructors”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
unknownfor the sibling AST singleton that also accepts every value while preserving the saferunknowntype
Signature
declare const any: AnySince v4.0.0
bigInt
Section titled “bigInt”Provides 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
BigIntfor the AST node class and string-codec behaviorisBigIntfor narrowing an AST to aBigIntnode
Signature
declare const bigInt: BigIntSince v4.0.0
boolean
Section titled “boolean”Provides 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
Booleanfor the AST node classLiteralfor exact boolean literal AST nodes
Signature
declare const boolean: BooleanSince v4.0.0
isPattern
Section titled “isPattern”Creates 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 source is stored in
annotations for serialization and arbitrary generation.
Gotchas
Use a non-global, non-sticky regular expression, or reset lastIndex
yourself, because RegExp.test is stateful for expressions with the g or
y flag.
Example (Validating an email pattern)
import { SchemaAST } from "effect"
const emailFilter = SchemaAST.isPattern(/^[^@]+@[^@]+$/)See
Filter
Signature
declare const isPattern: (regExp: globalThis.RegExp, annotations?: Schema.Annotations.Filter) => Filter<string>Since v4.0.0
Provides the singleton Never AST instance.
When to use
Use to reuse the canonical bottom-type AST node when constructing, comparing, or returning ASTs.
See
Neverfor the AST node classisNeverfor narrowing an AST to aNevernode
Signature
declare const never: NeverSince v4.0.0
number
Section titled “number”Provides 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
Numberfor the AST node class and serialization behaviorLiteralfor exact finite numeric literal AST nodes
Signature
declare const number: NumberSince v4.0.0
objectKeyword
Section titled “objectKeyword”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
ObjectKeywordfor the AST node classisObjectKeywordfor narrowing an AST to anObjectKeywordnode
Signature
declare const objectKeyword: ObjectKeywordSince v3.10.0
string
Section titled “string”Provides the singleton String AST instance.
When to use
Use as the shared SchemaAST node for unconstrained JavaScript strings.
See
Stringfor the AST node classisStringfor narrowing an AST to a string node
Signature
declare const string: StringSince v4.0.0
symbol
Section titled “symbol”Provides 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
UniqueSymbolfor an AST node that matches one specific symbol
Signature
declare const symbol: SymbolSince v4.0.0
unknown
Section titled “unknown”Provides 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
anyfor the singleton that accepts every value asany
Signature
declare const unknown: UnknownSince v4.0.0
Provides the singleton Void AST instance.
When to use
Use when constructing or comparing AST nodes for TypeScript void return
values whose result is intentionally ignored.
Details
The node parses any present runtime value as undefined; schemas may still
expose void on their typed decoded and encoded sides.
See
Voidfor the AST node classundefinedfor the sibling AST singleton that matches exactlyundefinedisVoidfor narrowing an AST to aVoidnode
Signature
declare const void: VoidSince v4.0.0
guards
Section titled “guards”Returns true if the value is an AST node (any variant).
Details
Uses the internal TypeId brand to distinguish AST nodes from arbitrary
objects.
See
AST
Signature
declare const isAST: (u: unknown) => u is ASTSince v4.0.0
Narrows an AST to Any.
When to use
Use when you need to inspect a schema AST and handle the Any node
variant specifically.
See
isUnknownfor the guard for theUnknownnode, whose parsed result is typed asunknownrather thanany
Signature
declare const isAny: (ast: AST) => ast is AnySince v4.0.0
isArrays
Section titled “isArrays”Narrows an AST to Arrays.
When to use
Use to recognize array-like AST nodes before reading their element, rest, or mutability metadata.
See
Arraysfor the AST node type narrowed by this guard
Signature
declare const isArrays: (ast: AST) => ast is ArraysSince v4.0.0
isBigInt
Section titled “isBigInt”Narrows an AST to BigInt.
When to use
Use to identify bigint AST nodes while inspecting or transforming schema ASTs.
See
BigIntfor the AST node matched by this guardbigIntfor the singleton instance; useisBigIntwhen narrowing an existingASTvalue
Signature
declare const isBigInt: (ast: AST) => ast is BigIntSince v4.0.0
isBoolean
Section titled “isBoolean”Narrows an AST to Boolean.
When to use
Use to identify the Boolean AST variant while inspecting, traversing, or
transforming schema definitions.
See
Booleanfor the AST node type matched by this guardbooleanfor the singleton instance to use when constructing a boolean AST directly
Signature
declare const isBoolean: (ast: AST) => ast is BooleanSince v4.0.0
isDeclaration
Section titled “isDeclaration”Narrows an AST to Declaration.
When to use
Use to recognize declaration AST nodes before running declaration-specific handling.
See
Declarationfor the AST node type narrowed by this guard
Signature
declare const isDeclaration: (ast: AST) => ast is DeclarationSince v3.10.0
isEnum
Section titled “isEnum”Narrows an AST to Enum.
When to use
Use to recognize enum AST nodes before reading enum cases or running enum-specific handling.
See
Enumfor the AST node type narrowed by this guard
Signature
declare const isEnum: (ast: AST) => ast is EnumSince v4.0.0
isLiteral
Section titled “isLiteral”Narrows an AST to Literal.
When to use
Use to recognize exact string, number, boolean, or bigint literal AST nodes.
See
Literalfor the AST node type narrowed by this guardLiteralValuefor the values stored by literal nodes
Signature
declare const isLiteral: (ast: AST) => ast is LiteralSince v3.10.0
isNever
Section titled “isNever”Narrows an AST to Never.
When to use
Use to detect the AST node for a schema that can never match before handling other schema variants.
See
Neverfor the AST node type narrowed by this guardneverfor the singletonNeverAST instance
Signature
declare const isNever: (ast: AST) => ast is NeverSince v4.0.0
isNull
Section titled “isNull”Narrows an AST to Null.
When to use
Use to recognize an AST node that represents exactly the null literal when
inspecting, traversing, or transforming schema ASTs.
See
Nullfor the AST node type narrowed by this guardnullfor the singletonNullAST instanceisLiteralfor exact primitive literal AST nodes
Signature
declare const isNull: (ast: AST) => ast is NullSince v4.0.0
isNumber
Section titled “isNumber”Narrows an AST to Number.
When to use
Use to detect Number AST nodes while inspecting, traversing, or transforming
schema ASTs.
Signature
declare const isNumber: (ast: AST) => ast is NumberSince v4.0.0
isObjectKeyword
Section titled “isObjectKeyword”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
ObjectKeywordfor the AST node matched by this guardobjectKeywordfor the singletonObjectKeywordAST instanceisObjectsfor struct and record AST nodes
Signature
declare const isObjectKeyword: (ast: AST) => ast is ObjectKeywordSince v3.10.0
isObjects
Section titled “isObjects”Narrows an AST to Objects.
Signature
declare const isObjects: (ast: AST) => ast is ObjectsSince v4.0.0
isString
Section titled “isString”Narrows an AST to String.
When to use
Use to detect schema AST nodes that match any string value while inspecting or transforming a Schema AST.
See
Stringfor the AST node class narrowed by this guardstringfor the singletonStringAST instanceisLiteralfor exact primitive literal AST nodes, including exact string literals
Signature
declare const isString: (ast: AST) => ast is StringSince v4.0.0
isSuspend
Section titled “isSuspend”Narrows an AST to Suspend.
Signature
declare const isSuspend: (ast: AST) => ast is SuspendSince v3.10.0
isSymbol
Section titled “isSymbol”Narrows an AST to Symbol.
When to use
Use to narrow an AST node before handling the Symbol variant for schemas
that accept any JavaScript symbol value.
See
isUniqueSymbolfor the sibling guard that narrows theUniqueSymbolvariant for one exact symbol value
Signature
declare const isSymbol: (ast: AST) => ast is SymbolSince v4.0.0
isTemplateLiteral
Section titled “isTemplateLiteral”Narrows an AST to TemplateLiteral.
Signature
declare const isTemplateLiteral: (ast: AST) => ast is TemplateLiteralSince v3.10.0
isUndefined
Section titled “isUndefined”Narrows an AST to Undefined.
When to use
Use to identify AST nodes that represent exactly the JavaScript undefined
value.
See
isVoidfor narrowing AST nodes that represent TypeScriptvoidinstead of exactundefined
Signature
declare const isUndefined: (ast: AST) => ast is UndefinedSince v4.0.0
isUnion
Section titled “isUnion”Narrows an AST to Union.
Signature
declare const isUnion: (ast: AST) => ast is Union<AST>Since v3.10.0
isUniqueSymbol
Section titled “isUniqueSymbol”Narrows an AST to UniqueSymbol.
Signature
declare const isUniqueSymbol: (ast: AST) => ast is UniqueSymbolSince v3.10.0
isUnknown
Section titled “isUnknown”Narrows an AST to Unknown.
When to use
Use when you need to inspect a schema AST and handle the Unknown node
variant specifically.
See
isAnyfor the guard for theAnynode, whose parsed result is typed asanyrather thanunknown
Signature
declare const isUnknown: (ast: AST) => ast is UnknownSince v4.0.0
isVoid
Section titled “isVoid”Narrows an AST to Void.
When to use
Use to identify AST nodes that represent the TypeScript void type before
handling Void-specific schema behavior.
See
isUndefinedfor narrowing AST nodes that represent the literalundefinedvalue instead of TypeScriptvoid
Signature
declare const isVoid: (ast: AST) => ast is VoidSince v4.0.0
models
Section titled “models”AST (type alias)
Section titled “AST (type alias)”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
Basefields:annotations,checks,encoding,context. - Discriminate on the
_tagfield (e.g."String","Objects","Union").
See
BaseisAST
Signature
type AST = | Declaration | Null | Undefined | Void | Never | Unknown | Any | String | Number | Boolean | BigInt | Symbol | Literal | UniqueSymbol | ObjectKeyword | Enum | TemplateLiteral | Arrays | Objects | Union | SuspendSince v3.10.0
Any (class)
Section titled “Any (class)”AST node representing the any type — every value matches.
See
anyisAny
Signature
declare class AnySince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Any"Arrays (class)
Section titled “Arrays (class)”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 itsContext.isOptionalistrue.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.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])const ast = schema.ast
if (SchemaAST.isArrays(ast)) { console.log(ast.elements.length) // 2 console.log(ast.rest.length) // 0}See
isArraysObjects
Signature
declare class Arrays { constructor( isMutable: boolean, elements: ReadonlyArray<AST>, rest: ReadonlyArray<AST>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks )}Since v4.0.0
_rebuild (method)
Section titled “_rebuild (method)”Signature
declare const _rebuild: ( recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Arrays"isMutable (property)
Section titled “isMutable (property)”Signature
readonly isMutable: booleanelements (property)
Section titled “elements (property)”Signature
readonly elements: ReadonlyArray<AST>rest (property)
Section titled “rest (property)”Signature
readonly rest: ReadonlyArray<AST>encodingChecks (property)
Section titled “encodingChecks (property)”Signature
readonly encodingChecks: readonly [Check<any>, ...Check<any>[]] | undefinedBase (class)
Section titled “Base (class)”Represents the abstract base class for all AST node variants.
Details
Every AST node extends Base and inherits these fields:
annotations— user-supplied metadata (identifier, title, description, arbitrary keys).checks— optionalChecksfor post-type-match validation.encoding— optionalEncodingchain for type ↔ wire transformations.context— optionalContextfor per-property metadata.
Subclasses add a _tag discriminant and variant-specific data.
See
AST
Signature
declare class Base { constructor( annotations: Schema.Annotations.Annotations | undefined = undefined, checks: Checks | undefined = undefined, encoding: Encoding | undefined = undefined, context: Context | undefined = undefined )}Since v4.0.0
toString (method)
Section titled “toString (method)”Signature
declare const toString: () => string[TypeId] (property)
Section titled “[TypeId] (property)”Signature
readonly [TypeId]: "~effect/Schema"_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: stringannotations (property)
Section titled “annotations (property)”Signature
readonly annotations: Schema.Annotations.Annotations | undefinedchecks (property)
Section titled “checks (property)”Signature
readonly checks: readonly [Check<any>, ...Check<any>[]] | undefinedencoding (property)
Section titled “encoding (property)”Signature
readonly encoding: readonly [Link, ...Link[]] | undefinedcontext (property)
Section titled “context (property)”Signature
readonly context: Context | undefinedBigInt (class)
Section titled “BigInt (class)”AST node matching any bigint value.
Details
When serialized to a string-based codec, bigints are converted to/from their decimal string representation.
See
bigIntisBigInt
Signature
declare class BigIntSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "BigInt"Boolean (class)
Section titled “Boolean (class)”AST node matching any boolean value (true or false).
See
booleanisBoolean
Signature
declare class BooleanSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Boolean"Check (type alias)
Section titled “Check (type alias)”A validation check — either a single Filter or a composite
FilterGroup.
Details
Stored in the Checks array on Base.checks.
See
FilterFilterGroup
Signature
type Check<T> = Filter<T> | FilterGroup<T>Since v4.0.0
Checks (type alias)
Section titled “Checks (type alias)”Non-empty array of validation Check values attached to an AST node
via Base.checks.
Details
Checks are run after basic type matching succeeds. They represent
refinements like minLength, pattern, int, etc.
See
CheckFilterFilterGroup
Signature
type Checks = readonly [Check<any>, ...Array<Check<any>>]Since v4.0.0
Context (class)
Section titled “Context (class)”Represents per-property metadata attached to AST nodes via Base.context.
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.defaultValue— anEncodingapplied during construction to supply missing values.annotations— key-level annotations (e.g. description of the key itself).
See
optionalKeyisOptional
Signature
declare class Context { constructor( isOptional: boolean, isMutable: boolean, /** Used for constructor default values (e.g. `withConstructorDefault` API) */ defaultValue: Encoding | undefined = undefined, annotations: Schema.Annotations.Key<unknown> | undefined = undefined )}Since v4.0.0
isOptional (property)
Section titled “isOptional (property)”Signature
readonly isOptional: booleanisMutable (property)
Section titled “isMutable (property)”Signature
readonly isMutable: booleandefaultValue (property)
Section titled “defaultValue (property)”Used for constructor default values (e.g. withConstructorDefault API)
Signature
readonly defaultValue: readonly [Link, ...Link[]] | undefinedannotations (property)
Section titled “annotations (property)”Signature
readonly annotations: Schema.Annotations.Key<unknown> | undefinedDeclaration (class)
Section titled “Declaration (class)”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.
See
isDeclaration
Signature
declare class Declaration { constructor( typeParameters: ReadonlyArray<AST>, run: ( typeParameters: ReadonlyArray<AST> ) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks )}Since v3.10.0
_rebuild (method)
Section titled “_rebuild (method)”Signature
declare const _rebuild: ( recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Declaration"typeParameters (property)
Section titled “typeParameters (property)”Signature
readonly typeParameters: ReadonlyArray<AST>run (property)
Section titled “run (property)”Signature
readonly run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>encodingChecks (property)
Section titled “encodingChecks (property)”Signature
readonly encodingChecks: readonly [Check<any>, ...Check<any>[]] | undefinedEncoding (type alias)
Section titled “Encoding (type alias)”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 Base.encoding. When undefined, the node has no
encoding transformation (type and encoded forms are identical).
See
LinktoEncoded
Signature
type Encoding = readonly [Link, ...Array<Link>]Since v4.0.0
Enum (class)
Section titled “Enum (class)”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
isEnum
Signature
declare class Enum { constructor( enums: ReadonlyArray<readonly [string, string | number]>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context )}Since v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Enum"enums (property)
Section titled “enums (property)”Signature
readonly enums: ReadonlyArray<readonly [string, string | number]>Filter (class)
Section titled “Filter (class)”Represents a single validation check attached to an AST node.
Details
run— the validation function. Returnsundefinedon success, or anIssueon failure.annotations— optional filter-level metadata (expected message, meta tags, 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
FilterGroupCheckisPattern
Signature
declare class Filter<E> { constructor( run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined, annotations: Schema.Annotations.Filter | undefined = undefined, /** * Whether the parsing process should be aborted after this check has failed. */ aborted: boolean = false )}Since v4.0.0
annotate (method)
Section titled “annotate (method)”Signature
declare const annotate: (annotations: Schema.Annotations.Filter) => Filter<E>abort (method)
Section titled “abort (method)”Signature
declare const abort: () => Filter<E>and (method)
Section titled “and (method)”Signature
declare const and: (other: Check<E>, annotations?: Schema.Annotations.Filter) => FilterGroup<E>_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Filter"run (property)
Section titled “run (property)”Signature
readonly run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefinedannotations (property)
Section titled “annotations (property)”Signature
readonly annotations: Schema.Annotations.Filter | undefinedaborted (property)
Section titled “aborted (property)”Whether the parsing process should be aborted after this check has failed.
Signature
readonly aborted: booleanFilterGroup (class)
Section titled “FilterGroup (class)”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
FilterCheck
Signature
declare class FilterGroup<E> { constructor( checks: readonly [Check<E>, ...Array<Check<E>>], annotations: Schema.Annotations.Filter | undefined = undefined )}Since v4.0.0
annotate (method)
Section titled “annotate (method)”Signature
declare const annotate: (annotations: Schema.Annotations.Filter) => FilterGroup<E>and (method)
Section titled “and (method)”Signature
declare const and: (other: Check<E>, annotations?: Schema.Annotations.Filter) => FilterGroup<E>_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "FilterGroup"checks (property)
Section titled “checks (property)”Signature
readonly checks: readonly [Check<E>, ...Check<E>[]]annotations (property)
Section titled “annotations (property)”Signature
readonly annotations: Schema.Annotations.Filter | undefinedIndexSignature (class)
Section titled “IndexSignature (class)”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.Stringforstringkeys,TemplateLiteralfor patterned keys).type— the value type SchemaAST.merge— optionalKeyValueCombinerfor handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
See
ObjectsPropertySignature
Signature
declare class IndexSignature { constructor(parameter: AST, type: AST, merge: KeyValueCombiner | undefined)}Since v3.10.0
parameter (property)
Section titled “parameter (property)”Signature
readonly parameter: IndexSignatureParametertype (property)
Section titled “type (property)”Signature
readonly type: ASTmerge (property)
Section titled “merge (property)”Signature
readonly merge: KeyValueCombiner | undefinedKeyValueCombiner (class)
Section titled “KeyValueCombiner (class)”Represents a bidirectional merge strategy for index signature key-value pairs.
Details
Used by IndexSignature when the same key appears multiple times
(e.g. from Schema.extend or overlapping records). Provides separate
decode and encode combiners that determine how duplicate entries are
merged.
See
IndexSignature
Signature
declare class KeyValueCombiner { constructor( decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined, encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined )}Since v4.0.0
decode (property)
Section titled “decode (property)”Signature
readonly decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefinedencode (property)
Section titled “encode (property)”Signature
readonly encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefinedLink (class)
Section titled “Link (class)”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
EncodingdecodeTo
Signature
declare class Link { constructor( to: AST, transformation: | SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any> )}Since v4.0.0
to (property)
Section titled “to (property)”Signature
readonly to: ASTtransformation (property)
Section titled “transformation (property)”Signature
readonly transformation: SchemaTransformation.Transformation<any, any, any, any> | SchemaTransformation.Middleware<any, any, any, any, any, any>Literal (class)
Section titled “Literal (class)”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. Numeric literals must be finite — Infinity, -Infinity,
and NaN are rejected at construction time.
Example (Creating a literal AST)
import { SchemaAST } from "effect"
const ast = new SchemaAST.Literal("active")console.log(ast.literal) // "active"See
LiteralValueisLiteral
Signature
declare class Literal { constructor( literal: LiteralValue, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context )}Since v3.10.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Literal"literal (property)
Section titled “literal (property)”Signature
readonly literal: LiteralValueLiteralValue (type alias)
Section titled “LiteralValue (type alias)”The set of primitive types that can appear as a Literal value.
See
Literal
Signature
type LiteralValue = string | number | boolean | bigintSince v3.10.0
Never (class)
Section titled “Never (class)”AST 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
neverisNever
Signature
declare class NeverSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Never"Null (class)
Section titled “Null (class)”AST node matching the null literal value.
Details
Parsing succeeds only when the input is exactly null.
See
nullisNull
Signature
declare class NullSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Null"Number (class)
Section titled “Number (class)”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
numberisNumber
Signature
declare class NumberSince v4.0.0
_match (method)
Section titled “_match (method)”Signature
declare const _match: (regexp: RegExp, s: string, options: ParseOptions) => number | undefined_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Number"ObjectKeyword (class)
Section titled “ObjectKeyword (class)”AST node matching the TypeScript object type — accepts objects, arrays,
and functions (anything non-primitive and non-null).
See
objectKeywordisObjectKeyword
Signature
declare class ObjectKeywordSince v3.10.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "ObjectKeyword"Objects (class)
Section titled “Objects (class)”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.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })const ast = schema.ast
if (SchemaAST.isObjects(ast)) { for (const ps of ast.propertySignatures) { console.log(ps.name, ps.type._tag) } // "name" "String"}See
isObjectsPropertySignatureIndexSignatureArrays
Signature
declare class Objects { constructor( propertySignatures: ReadonlyArray<PropertySignature>, indexSignatures: ReadonlyArray<IndexSignature>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks )}Since v4.0.0
_rebuild (method)
Section titled “_rebuild (method)”Signature
declare const _rebuild: ( recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Objects"propertySignatures (property)
Section titled “propertySignatures (property)”Signature
readonly propertySignatures: ReadonlyArray<PropertySignature>indexSignatures (property)
Section titled “indexSignatures (property)”Signature
readonly indexSignatures: ReadonlyArray<IndexSignature>encodingChecks (property)
Section titled “encodingChecks (property)”Signature
readonly encodingChecks: readonly [Check<any>, ...Check<any>[]] | undefinedPropertySignature (class)
Section titled “PropertySignature (class)”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
Objects
Signature
declare class PropertySignature { constructor(name: PropertyKey, type: AST)}Since v3.10.0
name (property)
Section titled “name (property)”Signature
readonly name: PropertyKeytype (property)
Section titled “type (property)”Signature
readonly type: ASTString (class)
Section titled “String (class)”AST node matching any string value.
See
stringisString
Signature
declare class StringSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "String"Suspend (class)
Section titled “Suspend (class)”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.
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))})
// The recursive branch is a Suspend nodeSee
isSuspend
Signature
declare class Suspend { constructor( thunk: () => AST, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context )}Since v3.10.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Suspend"thunk (property)
Section titled “thunk (property)”Signature
readonly thunk: () => ASTSymbol (class)
Section titled “Symbol (class)”AST 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
symbolisSymbol
Signature
declare class SymbolSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Symbol"TemplateLiteral (class)
Section titled “TemplateLiteral (class)”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
isTemplateLiteral
Signature
declare class TemplateLiteral { constructor( parts: ReadonlyArray<AST>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context )}Since v3.10.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "TemplateLiteral"parts (property)
Section titled “parts (property)”Signature
readonly parts: ReadonlyArray<AST>Undefined (class)
Section titled “Undefined (class)”AST node matching the undefined value.
Details
Parsing succeeds only when the input is exactly undefined.
See
undefinedisUndefined
Signature
declare class UndefinedSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Undefined"Union (class)
Section titled “Union (class)”AST node representing a union of schemas.
Details
types— the member AST nodes.mode—"anyOf"succeeds on the first match (like TypeScript unions);"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.
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)) { console.log(ast.types.length) // 2 console.log(ast.mode) // "anyOf"}See
isUnion
Signature
declare class Union<A> { constructor( types: ReadonlyArray<A>, mode: "anyOf" | "oneOf", annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks )}Since v3.10.0
_rebuild (method)
Section titled “_rebuild (method)”Signature
declare const _rebuild: ( recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Union<AST>_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Union"types (property)
Section titled “types (property)”Signature
readonly types: ReadonlyArray<A>mode (property)
Section titled “mode (property)”Signature
readonly mode: "anyOf" | "oneOf"encodingChecks (property)
Section titled “encodingChecks (property)”Signature
readonly encodingChecks: readonly [Check<any>, ...Check<any>[]] | undefinedUniqueSymbol (class)
Section titled “UniqueSymbol (class)”AST node matching a specific unique symbol value.
Details
Parsing succeeds only when the input is reference-equal to the stored
symbol.
See
isUniqueSymbol
Signature
declare class UniqueSymbol { constructor( symbol: symbol, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context )}Since v3.10.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "UniqueSymbol"symbol (property)
Section titled “symbol (property)”Signature
readonly symbol: symbolUnknown (class)
Section titled “Unknown (class)”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
unknownisUnknown
Signature
declare class UnknownSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Unknown"Void (class)
Section titled “Void (class)”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
undefinedfor the AST singleton that matches only exactundefinedvoidisVoid
Signature
declare class VoidSince v4.0.0
_tag (property)
Section titled “_tag (property)”Signature
readonly _tag: "Void"options
Section titled “options”ParseOptions (interface)
Section titled “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, output key ordering, check
execution, and asynchronous parser concurrency.
errors—"first"(default) stops at the first error;"all"collects every error.onExcessProperty—"ignore"(default) strips unknown object keys;"error"fails;"preserve"keeps them.propertyOrder—"none"(default) lets the system choose key order;"original"preserves input key order.disableChecks— skips validation checks while still applying defaults and transformations.concurrency— maximum number of async parse effects to run concurrently; defaults to1, or use"unbounded".
Signature
export interface ParseOptions { /** * Controls how many parsing errors are reported. * * **Details** * * The default, `"first"`, stops at the first error. Set the option to `"all"` * to collect every parsing error, which can help with debugging or with * presenting more complete error messages to a user. * * @default "first" */ readonly errors?: "first" | "all" | undefined
/** * Controls how object parsing handles keys that are not declared by the schema. * * **Details** * * The default, `"ignore"`, strips unspecified properties from the output. Use * `"error"` to fail when an excess property is present, or `"preserve"` to * keep excess properties in the output. * * @default "ignore" */ readonly onExcessProperty?: "ignore" | "error" | "preserve" | undefined
/** * The `propertyOrder` option provides control over the order of object fields * in the output. This feature is useful when the sequence of keys is * important for the consuming processes or when maintaining the input order * enhances readability and usability. * * **Details** * * By default, the `propertyOrder` option is set to `"none"`. This means that * the internal system decides the order of keys to optimize parsing speed. * * Setting `propertyOrder` to `"original"` ensures that the keys are ordered * as they appear in the input during the decoding/encoding process. * * **Gotchas** * * The key order for `"none"` should not be considered stable and may change * in future updates without notice. * * @default "none" */ readonly propertyOrder?: "none" | "original" | undefined
/** * Whether to disable checks while still applying defaults and * transformations. */ readonly disableChecks?: boolean | undefined
/** * The maximum number of async effects to run concurrently. * * @default 1 */ readonly concurrency?: number | "unbounded" | undefined}Since v3.10.0
predicates
Section titled “predicates”isOptional
Section titled “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
optionalKeyContext
Signature
declare const isOptional: (ast: AST) => booleanSince v4.0.0
transforming
Section titled “transforming”decodeTo
Section titled “decodeTo”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.transform and
Schema.transformOrFail. It appends a Link to the to node’s
encoding chain.
- Returns a new AST with the same type as
to.
See
LinkEncodingflip
Signature
declare const decodeTo: <A extends AST>( from: AST, to: A, transformation: SchemaTransformation.Transformation<any, any, any, any>) => ASince v4.0.0
Swaps 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
toTypetoEncoded
Signature
declare const flip: (ast: AST) => ASTSince v4.0.0
optionalKey
Section titled “optionalKey”Marks an AST node’s property key as optional by setting
Context.isOptional to true.
Details
Also propagates the optional flag through the last link of the encoding chain if present.
See
isOptionalContext
Signature
declare const optionalKey: <A extends AST>(ast: A) => ASince v4.0.0
toEncoded
Section titled “toEncoded”Returns 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.
Example (Getting the encoded AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromStringconst encodedAst = SchemaAST.toEncoded(schema.ast)console.log(encodedAst._tag) // "String"See
toTypeflip
Signature
declare const toEncoded: (ast: AST) => ASTSince v4.0.0
toType
Section titled “toType”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).
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromStringconst typeAst = SchemaAST.toType(schema.ast)console.log(typeAst._tag) // "Number"See
toEncodedflip
Signature
declare const toType: <A extends AST>(ast: A) => ASince v4.0.0