ObjectsAST 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"
}export class class Objectsclass Objects {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects extends class BaseRepresents 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 — optional
Checks
for post-type-match validation.
encoding — optional
Encoding
chain for type ↔ wire
transformations.
context — optional
Context
for per-property metadata.
Subclasses add a _tag discriminant and variant-specific data.
Base {
readonly Objects._tag: "Objects"_tag = "Objects"
readonly Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures: interface ReadonlyArray<T>ReadonlyArray<class PropertySignatureclass PropertySignature {
name: PropertyKey;
type: AST;
}
PropertySignature>
readonly Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures: interface ReadonlyArray<T>ReadonlyArray<class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature>
readonly Objects.encodingChecks: Checks | undefinedencodingChecks: type Checks = readonly [
Check<any>,
...Check<any>[]
]
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.
Checks | undefined
constructor(
propertySignatures: ReadonlyArray<PropertySignature>propertySignatures: interface ReadonlyArray<T>ReadonlyArray<class PropertySignatureclass PropertySignature {
name: PropertyKey;
type: AST;
}
PropertySignature>,
indexSignatures: ReadonlyArray<IndexSignature>indexSignatures: interface ReadonlyArray<T>ReadonlyArray<class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature>,
annotations: | Schema.Annotations.Annotations
| undefined
annotations?: import SchemaSchema.Annotations.interface Annotations.AnnotationsThis interface is used to define the annotations that can be attached to a
schema. You can extend this interface to define your own annotations.
Details
Note that both a missing key or undefined is used to indicate that the
annotation is not present.
This means that can remove any annotation by setting it to undefined.
Example (Defining your own annotations)
import { Schema } from "effect"
// Extend the Annotations interface with a custom `version` annotation
declare module "effect/Schema" {
namespace Annotations {
interface Annotations {
readonly version?:
| readonly [major: number, minor: number, patch: number]
| undefined
}
}
}
// The `version` annotation is now recognized by the TypeScript compiler
const schema = Schema.String.annotate({ version: [1, 2, 0] })
// const version: readonly [major: number, minor: number, patch: number] | undefined
const version = Schema.resolveAnnotations(schema)?.["version"]
if (version) {
// Access individual parts of the version
console.log(version[1])
// Output: 2
}
Annotations,
checks: Checkschecks?: type Checks = readonly [
Check<any>,
...Check<any>[]
]
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.
Checks,
encoding: Encodingencoding?: type Encoding = readonly [Link, ...Link[]]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).
Encoding,
context: Contextcontext?: class Contextclass Context {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
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 is readonly when false.
defaultValue — an
Encoding
applied during construction to
supply missing values.
annotations — key-level annotations (e.g. description of the key
itself).
Context,
encodingChecks: ChecksencodingChecks?: type Checks = readonly [
Check<any>,
...Check<any>[]
]
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.
Checks
) {
super(annotations: | Schema.Annotations.Annotations
| undefined
annotations, checks: Checkschecks, encoding: Encodingencoding, context: Contextcontext)
this.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures = propertySignatures: ReadonlyArray<PropertySignature>propertySignatures
this.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures = indexSignatures: ReadonlyArray<IndexSignature>indexSignatures
this.Objects.encodingChecks: Checks | undefinedencodingChecks = encodingChecks: ChecksencodingChecks
// Duplicate property signatures
const const duplicates: PropertyKey[]duplicates = propertySignatures: ReadonlyArray<PropertySignature>propertySignatures.ReadonlyArray<PropertySignature>.map<PropertyKey>(callbackfn: (value: PropertySignature, index: number, array: readonly PropertySignature[]) => PropertyKey, thisArg?: any): PropertyKey[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps) => ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname).Array<PropertyKey>.filter(predicate: (value: PropertyKey, index: number, array: PropertyKey[]) => unknown, thisArg?: any): PropertyKey[] (+1 overload)Returns the elements of an array that meet the condition specified in a callback function.
filter((name: PropertyKeyname, i: numberi, arr: PropertyKey[]arr) => arr: PropertyKey[]arr.Array<PropertyKey>.indexOf(searchElement: PropertyKey, fromIndex?: number): numberReturns the index of the first occurrence of a value in an array, or -1 if it is not present.
indexOf(name: PropertyKeyname) !== i: numberi)
if (const duplicates: PropertyKey[]duplicates.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length > 0) {
throw new var Error: ErrorConstructor
new (message?: string, options?: ErrorOptions) => Error (+1 overload)
Error(`Duplicate identifiers: ${var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
stringify(const duplicates: PropertyKey[]duplicates)}. ts(2300)`)
}
}
/** @internal */
Objects.getParser(recur: (ast: AST) => SchemaParser.Parser): SchemaParser.ParsergetParser(recur: (ast: AST) => SchemaParser.Parserrecur: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => import SchemaParserSchemaParser.Parser): import SchemaParserSchemaParser.Parser {
// oxlint-disable-next-line @typescript-eslint/no-this-alias
const const ast: thisast = this
const const expectedKeys: PropertyKey[]expectedKeys: interface Array<T>Array<type PropertyKey =
| string
| number
| symbol
PropertyKey> = []
const const expectedKeysSet: Set<PropertyKey>expectedKeysSet = new var Set: SetConstructor
new <PropertyKey>(iterable?: Iterable<PropertyKey> | null | undefined) => Set<PropertyKey> (+1 overload)
Set<type PropertyKey =
| string
| number
| symbol
PropertyKey>()
const const properties: Array<{
readonly ps: PropertySignature | IndexSignature
readonly parser: SchemaParser.Parser
readonly name: PropertyKey
readonly type: AST
}>
properties: interface Array<T>Array<{
readonly ps: PropertySignature | IndexSignatureps: class PropertySignatureclass PropertySignature {
name: PropertyKey;
type: AST;
}
PropertySignature | class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature
readonly parser: SchemaParser.Parserparser: import SchemaParserSchemaParser.Parser
readonly name: PropertyKeyname: type PropertyKey =
| string
| number
| symbol
PropertyKey
readonly type: ASTtype: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST
}> = []
for (const const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps of const ast: thisast.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures) {
const expectedKeys: PropertyKey[]expectedKeys.Array<PropertyKey>.push(...items: PropertyKey[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname)
const expectedKeysSet: Set<PropertyKey>expectedKeysSet.Set<PropertyKey>.add(value: PropertyKey): Set<PropertyKey>Appends a new element with a specified value to the end of the Set.
add(const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname)
const properties: Array<{
readonly ps: PropertySignature | IndexSignature
readonly parser: SchemaParser.Parser
readonly name: PropertyKey
readonly type: AST
}>
properties.function Array(...items: Array<{ readonly ps: PropertySignature | IndexSignature; readonly parser: SchemaParser.Parser; readonly name: PropertyKey; readonly type: AST }>): numberAppends new elements to the end of an array, and returns the new length of the array.
push({
ps: PropertySignature(property) ps: {
name: PropertyKey;
type: AST;
}
ps,
parser: SchemaParser.Parserparser: recur: (ast: AST) => SchemaParser.Parserrecur(const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype),
name: PropertyKeyname: const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname,
type: ASTtype: const ps: PropertySignatureconst ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype
})
}
const const indexCount: numberindexCount = const ast: thisast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length
// ---------------------------------------------
// handle empty struct
// ---------------------------------------------
if (const ast: thisast.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 ast: thisast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.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 function fromRefinement<T>(
ast: AST,
refinement: (input: unknown) => input is T
): SchemaParser.Parser
fromRefinement(const ast: thisast, import PredicatePredicate.function isNotNullish<A>(
input: A
): input is NonNullable<A>
Checks whether a value is not null and not undefined.
When to use
Use when you need a Predicate refinement that filters out nullish values
but keeps other falsy ones.
Details
Uses input != null.
Example (Filtering non-nullish values)
import { Predicate } from "effect"
const values = [0, null, "", undefined]
const present = values.filter(Predicate.isNotNullish)
console.log(present)
isNotNullish)
}
const const parseIndexes:
| ((
initialState: {
readonly oinput: Option.Option<unknown>
readonly input: Record<
PropertyKey,
unknown
>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues:
| Array<SchemaIssue.Issue>
| undefined
},
items: ReadonlyArray<
[key: PropertyKey, is: IndexSignature]
>,
options?: IterateEagerOptions
) =>
| Effect.Effect<
void,
SchemaIssue.Issue,
any
>
| undefined)
| undefined
parseIndexes = const indexCount: numberindexCount > 0 ?
iterateEager<S, A>(): <X, E, R, E2>(options: { readonly onItem: (state: S, item: A, index: number) => Effect.Effect<X, E, R>; readonly step: (state: NoInfer<S>, item: A, exit: Exit.Exit<X, E>, index: number) => Exit.Exit<void, E2> | void }) => (initialState: S, items: ReadonlyArray<A>, options?: IterateEagerOptions) => Effect.Effect<void, E | E2, R> | undefinediterateEager<{
readonly oinput: Option.Option<unknown>oinput: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<unknown>
readonly input: Record<PropertyKey, unknown>input: 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, unknown>
readonly options: ParseOptions(property) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options: ParseOptions
readonly out: Record<PropertyKey, unknown>out: 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, unknown>
issues: Array<SchemaIssue.Issue> | undefinedissues: interface Array<T>Array<import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue> | undefined
}, [PropertyKeykey: type PropertyKey =
| string
| number
| symbol
PropertyKey, IndexSignatureRepresents 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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
is: class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature]>()({
onItem: (
s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
},
args_1: [key: PropertyKey, is: IndexSignature]
) => Effect.Effect<void, SchemaIssue.Issue, any>
onItem: import EffectEffect.const fnUntracedEager: <Effect.Effect<any, SchemaIssue.Issue, never> | Effect.Effect<Exit.Exit<Option.Option<unknown>, SchemaIssue.Issue>, never, any>, void, [s: {
readonly oinput: Option.Option<unknown>;
readonly input: Record<PropertyKey, unknown>;
readonly options: ParseOptions;
readonly out: Record<PropertyKey, unknown>;
issues: Array<SchemaIssue.Issue> | undefined;
}, [key: PropertyKey, is: IndexSignature]]>(body: (this: unassigned, s: {
readonly oinput: Option.Option<unknown>;
readonly input: Record<PropertyKey, unknown>;
readonly options: ParseOptions;
readonly out: Record<PropertyKey, unknown>;
issues: Array<SchemaIssue.Issue> | undefined;
}, args_1: [key: ...]) => Generator<...>) => (s: {
readonly oinput: Option.Option<unknown>;
readonly input: Record<PropertyKey, unknown>;
readonly options: ParseOptions;
readonly out: Record<PropertyKey, unknown>;
issues: Array<SchemaIssue.Issue> | undefined;
}, args_1: [key: ...]) => Effect.Effect<...> (+41 overloads)
fnUntracedEager(function*(
s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s,
[key: PropertyKeykey, is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is]
) {
const const parserKey: SchemaParser.ParserparserKey = recur: (ast: AST) => SchemaParser.Parserrecur(const parameterFromPropertyKey: (
ast: AST
) => AST
parameterFromPropertyKey(is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.parameter: IndexSignatureParameterparameter))
const const effKey: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effKey: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effKey = const parserKey: SchemaParser.Parser
;(
input: Option.Option<unknown>,
options: ParseOptions
) =>
Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
parserKey(import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(key: PropertyKeykey), s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.options: ParseOptions(property) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options)
const const exitKey: Exit.Exit<
Option.Option<PropertyKey>,
SchemaIssue.Issue
>
exitKey = (effectIsExit<A, E, R>(effect: Effect.Effect<A, E, R>): effect is Exit.Exit<A, E>effectIsExit(const effKey: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effKey: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effKey) ? const effKey: Exit.Exit<
Option.Option<unknown>,
SchemaIssue.Issue
>
effKey : yield* import EffectEffect.const exit: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Exit.Exit<A, E>, never, R>
Transforms an effect to encapsulate both failure and success using the Exit
data type.
When to use
Use when you need to inspect the full outcome, including typed failures, defects,
and interruptions.
Details
exit wraps an effect's success or failure inside an Exit type, allowing
you to handle both cases explicitly.
The resulting effect cannot fail because the failure is encapsulated within
the Exit.Failure type. The error type is set to never, indicating that
the effect is structured to never fail directly.
Example (Capturing completion as Exit)
import { Effect } from "effect"
const success = Effect.succeed(42)
const failure = Effect.fail("Something went wrong")
const program1 = Effect.exit(success)
const program2 = Effect.exit(failure)
Effect.runPromise(program1).then(console.log)
// { _id: 'Exit', _tag: 'Success', value: 42 }
Effect.runPromise(program2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
exit(const effKey: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effKey: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effKey)) as import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<
import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<type PropertyKey =
| string
| number
| symbol
PropertyKey>,
import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue
>
if (const exitKey: Exit.Exit<
Option.Option<PropertyKey>,
SchemaIssue.Issue
>
exitKey._tag: "Success" | "Failure"_tag === "Failure") {
const const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
eff = const wrapPropertyKeyIssue: (
s: {
readonly oinput: Option.Option<unknown>
readonly options: ParseOptions
issues: Array<SchemaIssue.Issue> | undefined
},
ast: AST,
key: PropertyKey,
exit: Exit.Failure<any, SchemaIssue.Issue>
) =>
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
wrapPropertyKeyIssue(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s, const ast: thisast, key: PropertyKeykey, const exitKey: Exit.Failure<
Option.Option<PropertyKey>,
SchemaIssue.Issue
>
const exitKey: {
_tag: "Failure";
cause: Cause.Cause<E>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitKey)
if (const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
eff) yield* const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
eff
return
}
const const value: Option.Option<unknown>value: import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<unknown> = import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.input: Record<PropertyKey, unknown>input[key: PropertyKeykey])
const const parserValue: SchemaParser.ParserparserValue = recur: (ast: AST) => SchemaParser.Parserrecur(is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.type: ASTtype)
const const effValue: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effValue: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effValue = const parserValue: SchemaParser.Parser
;(
input: Option.Option<unknown>,
options: ParseOptions
) =>
Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
parserValue(const value: Option.Option<unknown>value, s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.options: ParseOptions(property) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options)
const const exitValue: Exit.Exit<
Option.Option<unknown>,
SchemaIssue.Issue
>
exitValue = effectIsExit<A, E, R>(effect: Effect.Effect<A, E, R>): effect is Exit.Exit<A, E>effectIsExit(const effValue: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effValue: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effValue) ? const effValue: Exit.Exit<
Option.Option<unknown>,
SchemaIssue.Issue
>
effValue : yield* import EffectEffect.const exit: <A, E, R>(
self: Effect<A, E, R>
) => Effect<Exit.Exit<A, E>, never, R>
Transforms an effect to encapsulate both failure and success using the Exit
data type.
When to use
Use when you need to inspect the full outcome, including typed failures, defects,
and interruptions.
Details
exit wraps an effect's success or failure inside an Exit type, allowing
you to handle both cases explicitly.
The resulting effect cannot fail because the failure is encapsulated within
the Exit.Failure type. The error type is set to never, indicating that
the effect is structured to never fail directly.
Example (Capturing completion as Exit)
import { Effect } from "effect"
const success = Effect.succeed(42)
const failure = Effect.fail("Something went wrong")
const program1 = Effect.exit(success)
const program2 = Effect.exit(failure)
Effect.runPromise(program1).then(console.log)
// { _id: 'Exit', _tag: 'Success', value: 42 }
Effect.runPromise(program2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
exit(const effValue: Effect.Effect<
Option.Option<unknown>,
SchemaIssue.Issue,
any
>
const effValue: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
effValue)
if (const exitValue: Exit.Exit<
Option.Option<unknown>,
SchemaIssue.Issue
>
exitValue._tag: "Success" | "Failure"_tag === "Failure") {
const const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
eff = const wrapPropertyKeyIssue: (
s: {
readonly oinput: Option.Option<unknown>
readonly options: ParseOptions
issues: Array<SchemaIssue.Issue> | undefined
},
ast: AST,
key: PropertyKey,
exit: Exit.Failure<any, SchemaIssue.Issue>
) =>
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
wrapPropertyKeyIssue(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s, const ast: thisast, key: PropertyKeykey, const exitValue: Exit.Failure<
Option.Option<unknown>,
SchemaIssue.Issue
>
const exitValue: {
_tag: "Failure";
cause: Cause.Cause<E>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitValue)
if (const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
| undefined
eff) yield* const eff:
| Exit.Failure<any, SchemaIssue.Issue>
| Exit.Success<never, SchemaIssue.Composite>
eff
return
} else if (const exitKey: Exit.Success<
Option.Option<PropertyKey>,
SchemaIssue.Issue
>
const exitKey: {
_tag: "Success";
value: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitKey.Success<Option<PropertyKey>, Issue>.value: Option.Option<PropertyKey>value._tag: "None" | "Some"_tag === "Some" && const exitValue: Exit.Success<
Option.Option<unknown>,
SchemaIssue.Issue
>
const exitValue: {
_tag: "Success";
value: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitValue.Success<Option<unknown>, Issue>.value: Option.Option<unknown>value._tag: "None" | "Some"_tag === "Some") {
const const k2: PropertyKeyk2 = const exitKey: Exit.Success<
Option.Option<PropertyKey>,
SchemaIssue.Issue
>
const exitKey: {
_tag: "Success";
value: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitKey.Success<Option<PropertyKey>, Issue>.value: Option.Some<PropertyKey>(property) Success<Option<PropertyKey>, Issue>.value: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
value.Some<PropertyKey>.value: PropertyKeyvalue
if (const expectedKeysSet: Set<PropertyKey>expectedKeysSet.Set<PropertyKey>.has(value: PropertyKey): booleanhas(key: PropertyKeykey) || const expectedKeysSet: Set<PropertyKey>expectedKeysSet.Set<PropertyKey>.has(value: PropertyKey): booleanhas(const k2: PropertyKeyk2)) {
return
}
const const v2: unknownv2 = const exitValue: Exit.Success<
Option.Option<unknown>,
SchemaIssue.Issue
>
const exitValue: {
_tag: "Success";
value: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exitValue.Success<Option<unknown>, Issue>.value: Option.Some<unknown>(property) Success<Option<unknown>, Issue>.value: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
value.Some<unknown>.value: unknownvalue
if (is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefinedmerge && is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefined(property) IndexSignature.merge: {
decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
flip: () => KeyValueCombiner;
}
merge.KeyValueCombiner.decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefineddecode && var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.hasOwn(o: object, v: PropertyKey): booleanDetermines whether an object has a property with the specified name.
hasOwn(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.out: Record<PropertyKey, unknown>out, const k2: PropertyKeyk2)) {
const [const k: PropertyKeyk, const v: anyv] = is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefined(property) IndexSignature.merge: {
decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
encode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined;
flip: () => KeyValueCombiner;
}
merge.KeyValueCombiner.decode: Combiner.Combiner<readonly [key: PropertyKey, value: any]> | undefined(property) KeyValueCombiner.decode: {
combine: (self: A, that: A) => A;
}
decode.Combiner<readonly [key: PropertyKey, value: any]>.combine: (self: readonly [key: PropertyKey, value: any], that: readonly [key: PropertyKey, value: any]) => readonly [key: PropertyKey, value: any]Combines two values into a new value.
When to use
Use to merge two values according to this combining strategy.
combine([const k2: PropertyKeyk2, s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.out: Record<PropertyKey, unknown>out[const k2: PropertyKeyk2]], [const k2: PropertyKeyk2, const v2: unknownv2])
import internalRecordinternalRecord.function set<PropertyKey, any>(
self: Record<PropertyKey, any>,
key: PropertyKey,
value: any
): Record<PropertyKey, any>
set(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.out: Record<PropertyKey, unknown>out, const k: PropertyKeyk, const v: anyv)
} else {
import internalRecordinternalRecord.function set<PropertyKey, unknown>(
self: Record<PropertyKey, unknown>,
key: PropertyKey,
value: unknown
): Record<PropertyKey, unknown>
set(s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
s.out: Record<PropertyKey, unknown>out, const k2: PropertyKeyk2, const v2: unknownv2)
}
}
}),
step: (
_s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
},
_: [key: PropertyKey, is: IndexSignature],
exit: Exit.Exit<void, SchemaIssue.Issue>
) =>
| Exit.Failure<void, SchemaIssue.Issue>
| undefined
step: (_s: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
}
_s, _: [key: PropertyKey, is: IndexSignature](parameter) _: {
0: PropertyKey;
1: IndexSignature;
length: 2;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => PropertyKey | IndexSignature | undefined;
push: (...items: Array<PropertyKey | IndexSignature>) => number;
concat: { (...items: Array<ConcatArray<PropertyKey | IndexSignature>>): Array<PropertyKey | IndexSignature>; (...items: Array<PropertyKey | IndexSignature | ConcatArray<PropertyKey | IndexSignature>>): Array<PropertyKey | IndexSignature> };
join: (separator?: string) => string;
reverse: () => Array<PropertyKey | IndexSignature>;
shift: () => PropertyKey | IndexSignature | undefined;
slice: (start?: number, end?: number) => Array<PropertyKey | IndexSignature>;
sort: (compareFn?: ((a: PropertyKey | IndexSignature, b: PropertyKey | IndexSignature) => number) | undefined) => [key: PropertyKey, is: IndexSignature];
splice: { (start: number, deleteCount?: number): Array<PropertyKey | IndexSignature>; (start: number, deleteCount: number, ...items: Array<PropertyKey | IndexSignature>): Array<PropertyKey | IndexSignature> };
unshift: (...items: Array<PropertyKey | IndexSignature>) => number;
indexOf: (searchElement: PropertyKey | IndexSignature, fromIndex?: number) => number;
lastIndexOf: (searchElement: PropertyKey | IndexSignature, fromIndex?: number) => number;
every: { (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => value is S, thisArg?: any): this is S[]; (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<Proper…;
some: (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => void, thisArg?: any) => void;
map: (callbackfn: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => value is S, thisArg?: any): Array<S>; (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyK…;
reduce: { (callbackfn: (previousValue: PropertyKey | IndexSignature, currentValue: PropertyKey | IndexSignature, currentIndex: number, array: Array<PropertyKey | IndexSignature>) => PropertyKey | IndexSignature): PropertyKey | IndexSignature; (cal…;
reduceRight: { (callbackfn: (previousValue: PropertyKey | IndexSignature, currentValue: PropertyKey | IndexSignature, currentIndex: number, array: Array<PropertyKey | IndexSignature>) => PropertyKey | IndexSignature): PropertyKey | IndexSignature; (cal…;
find: { (predicate: (value: PropertyKey | IndexSignature, index: number, obj: Array<PropertyKey | IndexSignature>) => value is S, thisArg?: any): S | undefined; (predicate: (value: PropertyKey | IndexSignature, index: number, obj: Array<Property…;
findIndex: (predicate: (value: PropertyKey | IndexSignature, index: number, obj: Array<PropertyKey | IndexSignature>) => unknown, thisArg?: any) => number;
fill: (value: PropertyKey | IndexSignature, start?: number, end?: number) => [key: PropertyKey, is: IndexSignature];
copyWithin: (target: number, start: number, end?: number) => [key: PropertyKey, is: IndexSignature];
entries: () => ArrayIterator<[number, PropertyKey | IndexSignature]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<PropertyKey | IndexSignature>;
includes: (searchElement: PropertyKey | IndexSignature, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => PropertyKey | IndexSignature | undefined;
findLast: { (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => value is S, thisArg?: any): S | undefined; (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<Prop…;
findLastIndex: (predicate: (value: PropertyKey | IndexSignature, index: number, array: Array<PropertyKey | IndexSignature>) => unknown, thisArg?: any) => number;
toReversed: () => Array<PropertyKey | IndexSignature>;
toSorted: (compareFn?: ((a: PropertyKey | IndexSignature, b: PropertyKey | IndexSignature) => number) | undefined) => Array<PropertyKey | IndexSignature>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<PropertyKey | IndexSignature>): Array<PropertyKey | IndexSignature>; (start: number, deleteCount?: number): Array<PropertyKey | IndexSignature> };
with: (index: number, value: PropertyKey | IndexSignature) => Array<PropertyKey | IndexSignature>;
}
_, exit: Exit.Exit<void, SchemaIssue.Issue>exit: import ExitExit.type Exit<A, E = never> = Exit.Success<A, E> | Exit.Failure<A, E>Represents the result of an Effect computation.
When to use
Use when you need to synchronously inspect whether an Effect computation
succeeded or failed.
Details
An Exit<A, E> is either Success<A, E> containing a value of type A, or
Failure<A, E> containing a Cause<E> describing why the computation
failed.
Since Exit is also an Effect, you can yield it inside Effect.gen.
Example (Pattern matching on an Exit)
import { Exit } from "effect"
const success: Exit.Exit<number> = Exit.succeed(42)
const failure: Exit.Exit<number, string> = Exit.fail("error")
const result = Exit.match(success, {
onSuccess: (value) => `Got value: ${value}`,
onFailure: (cause) => `Got error: ${cause}`
})
Namespace containing helper types shared by Exit values.
When to use
Use to reference helper types that describe the shared structure of Exit
values.
Exit<void, import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue>) => exit: Exit.Exit<void, SchemaIssue.Issue>exit._tag: "Success" | "Failure"_tag === "Failure" ? exit: Exit.Exit<void, SchemaIssue.Issue>(parameter) exit: {
_tag: "Failure";
cause: Cause.Cause<E>;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
exit : var undefinedundefined
}) :
var undefinedundefined
return import EffectEffect.const fnUntracedEager: <Effect.Effect<void, SchemaIssue.Issue, any>, Option.None<unknown> | Option.Some<Record<PropertyKey, unknown>>, [oinput: Option.Option<unknown>, options: ParseOptions]>(body: (this: unassigned, oinput: Option.Option<unknown>, options: ParseOptions) => Generator<Effect.Effect<void, SchemaIssue.Issue, any>, Option.None<unknown> | Option.Some<Record<PropertyKey, unknown>>, never>) => (oinput: Option.Option<...>, options: ParseOptions) => Effect.Effect<...> (+41 overloads)fnUntracedEager(function*(oinput: Option.Option<unknown>oinput, options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options) {
if (oinput: Option.Option<unknown>oinput._tag: "None" | "Some"_tag === "None") {
return oinput: Option.None<unknown>(parameter) oinput: {
_tag: "None";
_op: "None";
valueOrUndefined: undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput
}
const const input: Record<PropertyKey, unknown>input = oinput: Option.Some<unknown>(parameter) oinput: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput.Some<unknown>.value: unknownvalue as 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, unknown>
// If the input is not a record, return early with an error
if (!(typeof const input: Record<PropertyKey, unknown>input === "object" && const input: Record<PropertyKey, unknown>input !== null && !var Array: ArrayConstructorArray.ArrayConstructor.isArray(arg: any): arg is any[]isArray(const input: Record<PropertyKey, unknown>input))) {
return yield* import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(new import SchemaIssueSchemaIssue.constructor InvalidType(ast: AST, actual: Option.Option<unknown>): SchemaIssue.InvalidTypeRepresents a schema issue produced when the runtime type of the input does not match the type
expected by the schema (e.g. got null when string was expected).
When to use
Use when you need to detect basic type mismatches, such as a wrong primitive
or null where an object was expected.
Details
ast is the schema node that expected a different type.
actual is Option.some(value) when the input was present, or
Option.none() when no value was provided.
- The default formatter renders this as
"Expected <type>, got <actual>".
Example (Formatting output)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.String)(42)
} catch (e) {
if (Schema.isSchemaError(e)) {
console.log(String(e.issue))
// "Expected string, got 42"
}
}
InvalidType(const ast: thisast, oinput: Option.Some<unknown>(parameter) oinput: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput))
}
const const out: Record<PropertyKey, unknown>out: 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, unknown> = {}
const const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state = {
ast: thisast,
oinput: Option.Some<unknown>(property) oinput: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput,
input: Record<PropertyKey, unknown>input,
out: Record<PropertyKey, unknown>out,
issues: | [SchemaIssue.Issue, ...SchemaIssue.Issue[]]
| undefined
issues: var undefinedundefined as import ArrArr.type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<import SchemaIssueSchemaIssue.type Issue =
| SchemaIssue.Leaf
| SchemaIssue.Filter
| SchemaIssue.Encoding
| SchemaIssue.Pointer
| SchemaIssue.Composite
| SchemaIssue.AnyOf
The root discriminated union of all validation error nodes.
When to use
Use when typing the error channel in Effect<A, Issue, R> results from
schema parsing, or when writing custom formatters or issue-tree walkers.
Details
Every node has a _tag field for pattern-matching. The union includes both
terminal
Leaf
types and composite types that wrap inner issues:
Filter
,
Encoding
,
Pointer
,
Composite
,
AnyOf
. All Issue instances have a toString() that delegates to
the default formatter, so String(issue) produces a human-readable message.
Issue> | undefined,
options: ParseOptions(property) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options
}
const const errorsAllOption: booleanerrorsAllOption = options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options.ParseOptions.errors?: "first" | "all" | undefinedControls 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.
errors === "all"
const const onExcessPropertyError: booleanonExcessPropertyError = options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options.ParseOptions.onExcessProperty?: "ignore" | "error" | "preserve" | undefinedControls 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.
onExcessProperty === "error"
const const onExcessPropertyPreserve: booleanonExcessPropertyPreserve = options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options.ParseOptions.onExcessProperty?: "ignore" | "error" | "preserve" | undefinedControls 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.
onExcessProperty === "preserve"
// ---------------------------------------------
// handle excess properties
// ---------------------------------------------
let let inputKeys: PropertyKey[] | undefinedinputKeys: interface Array<T>Array<type PropertyKey =
| string
| number
| symbol
PropertyKey> | undefined
if (const ast: thisast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.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 onExcessPropertyError: booleanonExcessPropertyError || const onExcessPropertyPreserve: booleanonExcessPropertyPreserve)) {
let inputKeys: PropertyKey[] | undefinedinputKeys = Reflect.function Reflect.ownKeys(target: object): (string | symbol)[]Returns the string and symbol keys of the own properties of an object. The own properties of an object
are those that are defined directly on that object, and are not inherited from the object's prototype.
ownKeys(const input: Record<PropertyKey, unknown>input)
for (let let i: numberi = 0; let i: numberi < let inputKeys: PropertyKey[]inputKeys.Array<T>.length: numberGets or sets the length of the array. This is a number one higher than the highest index in the array.
length; let i: numberi++) {
const const key: PropertyKeykey = let inputKeys: PropertyKey[]inputKeys[let i: numberi]
if (!const expectedKeysSet: Set<PropertyKey>expectedKeysSet.Set<PropertyKey>.has(value: PropertyKey): booleanhas(const key: PropertyKeykey)) {
// key is unexpected
if (const onExcessPropertyError: booleanonExcessPropertyError) {
const const issue: SchemaIssue.Pointerconst issue: {
_tag: 'Pointer';
path: ReadonlyArray<PropertyKey>;
issue: Issue;
toString: (this: Issue) => string;
}
issue = new import SchemaIssueSchemaIssue.constructor Pointer(path: ReadonlyArray<PropertyKey>, issue: SchemaIssue.Issue): SchemaIssue.PointerWraps an inner
Issue
with a property-key path, indicating where in
a nested structure the error occurred.
When to use
Use when you need to walk the issue tree to accumulate path segments for error
reporting.
Details
path is an array of property keys (strings, numbers, or symbols).
- Has no
actual value —
getActual
returns Option.none().
- Formatters concatenate nested
Pointer paths into a single path like
["a"]["b"][0].
Pointer([const key: PropertyKeykey], new import SchemaIssueSchemaIssue.constructor UnexpectedKey(ast: AST, actual: unknown): SchemaIssue.UnexpectedKeyRepresents a schema issue produced when an input object or tuple contains a key/index not
declared by the schema.
When to use
Use when you need to detect excess properties during strict struct/tuple
validation.
Details
actual is the raw value at the unexpected key (plain unknown).
ast is the schema that was being validated against.
annotations on ast may contain a custom messageUnexpectedKey.
UnexpectedKey(const ast: thisast, const input: Record<PropertyKey, unknown>input[const key: PropertyKeykey]))
if (const errorsAllOption: booleanerrorsAllOption) {
if (const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state.issues: | [SchemaIssue.Issue, ...SchemaIssue.Issue[]]
| undefined
issues) {
const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state.issues: [
SchemaIssue.Issue,
...SchemaIssue.Issue[]
]
(property) issues: {
0: SchemaIssue.Issue;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => SchemaIssue.Issue | undefined;
push: (...items: Array<SchemaIssue.Issue>) => number;
concat: { (...items: Array<ConcatArray<SchemaIssue.Issue>>): Array<SchemaIssue.Issue>; (...items: Array<SchemaIssue.Issue | ConcatArray<SchemaIssue.Issue>>): Array<SchemaIssue.Issue> };
join: (separator?: string) => string;
reverse: () => Array<SchemaIssue.Issue>;
shift: () => SchemaIssue.Issue | undefined;
slice: (start?: number, end?: number) => Array<SchemaIssue.Issue>;
sort: (compareFn?: ((a: SchemaIssue.Issue, b: SchemaIssue.Issue) => number) | undefined) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
splice: { (start: number, deleteCount?: number): Array<SchemaIssue.Issue>; (start: number, deleteCount: number, ...items: Array<SchemaIssue.Issue>): Array<SchemaIssue.Issue> };
unshift: (...items: Array<SchemaIssue.Issue>) => number;
indexOf: (searchElement: SchemaIssue.Issue, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaIssue.Issue, fromIndex?: number) => number;
every: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): this is S[]; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg…;
some: (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: …;
reduce: { (callbackfn: (previousValue: SchemaIssue.Issue, currentValue: SchemaIssue.Issue, currentIndex: number, array: Array<SchemaIssue.Issue>) => SchemaIssue.Issue): SchemaIssue.Issue; (callbackfn: (previousValue: SchemaIssue.Issue, currentValu…;
reduceRight: { (callbackfn: (previousValue: SchemaIssue.Issue, currentValue: SchemaIssue.Issue, currentIndex: number, array: Array<SchemaIssue.Issue>) => SchemaIssue.Issue): SchemaIssue.Issue; (callbackfn: (previousValue: SchemaIssue.Issue, currentValu…;
find: { (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => unknown, thisArg?:…;
findIndex: (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => number;
fill: (value: SchemaIssue.Issue, start?: number, end?: number) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
copyWithin: (target: number, start: number, end?: number) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
entries: () => ArrayIterator<[number, SchemaIssue.Issue]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaIssue.Issue>;
includes: (searchElement: SchemaIssue.Issue, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaIssue.Issue | undefined;
findLast: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisA…;
findLastIndex: (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaIssue.Issue>;
toSorted: (compareFn?: ((a: SchemaIssue.Issue, b: SchemaIssue.Issue) => number) | undefined) => Array<SchemaIssue.Issue>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaIssue.Issue>): Array<SchemaIssue.Issue>; (start: number, deleteCount?: number): Array<SchemaIssue.Issue> };
with: (index: number, value: SchemaIssue.Issue) => Array<SchemaIssue.Issue>;
}
issues.Array<Issue>.push(...items: SchemaIssue.Issue[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const issue: SchemaIssue.Pointerconst issue: {
_tag: 'Pointer';
path: ReadonlyArray<PropertyKey>;
issue: Issue;
toString: (this: Issue) => string;
}
issue)
} else {
const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state.issues: | [SchemaIssue.Issue, ...SchemaIssue.Issue[]]
| undefined
issues = [const issue: SchemaIssue.Pointerconst issue: {
_tag: 'Pointer';
path: ReadonlyArray<PropertyKey>;
issue: Issue;
toString: (this: Issue) => string;
}
issue]
}
continue
} else {
return yield* import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(new import SchemaIssueSchemaIssue.constructor Composite(ast: AST, actual: Option.Option<unknown>, issues: readonly [SchemaIssue.Issue, ...Array<SchemaIssue.Issue>]): SchemaIssue.CompositeRepresents a schema issue that groups multiple child issues under a single schema node.
When to use
Use when you need to walk the issue tree for struct/tuple schemas that collect
all field errors rather than failing on the first.
Details
issues is a non-empty readonly array (at least one child).
actual is Option.some(value) when the input was present, or
Option.none() when absent.
- Formatters flatten
Composite by recursing into each child.
Composite(const ast: thisast, oinput: Option.Some<unknown>(parameter) oinput: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput, [const issue: SchemaIssue.Pointerconst issue: {
_tag: 'Pointer';
path: ReadonlyArray<PropertyKey>;
issue: Issue;
toString: (this: Issue) => string;
}
issue]))
}
} else {
// preserve key
import internalRecordinternalRecord.function set<PropertyKey, unknown>(
self: Record<PropertyKey, unknown>,
key: PropertyKey,
value: unknown
): Record<PropertyKey, unknown>
set(const out: Record<PropertyKey, unknown>out, const key: PropertyKeykey, const input: Record<PropertyKey, unknown>input[const key: PropertyKeykey])
}
}
}
}
const const concurrency:
| {
concurrency: number
}
| undefined
concurrency = const resolveConcurrency: (
value: number | "unbounded" | undefined
) =>
| {
concurrency: number
}
| undefined
resolveConcurrency(options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options?.ParseOptions.concurrency?: number | "unbounded" | undefinedThe maximum number of async effects to run concurrently.
concurrency)
// ---------------------------------------------
// handle property signatures
// ---------------------------------------------
const const eff:
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
eff = const parseProperties: (
initialState: {
readonly ast: AST
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
},
items: ReadonlyArray<ParsedProperty>,
options?: IterateEagerOptions
) =>
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
parseProperties(const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state, const properties: Array<{
readonly ps: PropertySignature | IndexSignature
readonly parser: SchemaParser.Parser
readonly name: PropertyKey
readonly type: AST
}>
properties, const concurrency:
| {
concurrency: number
}
| undefined
concurrency)
if (const eff:
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
eff) yield* const eff: Effect.Effect<
void,
SchemaIssue.Issue,
any
>
const eff: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
eff
// ---------------------------------------------
// handle index signatures
// ---------------------------------------------
if (const parseIndexes:
| ((
initialState: {
readonly oinput: Option.Option<unknown>
readonly input: Record<
PropertyKey,
unknown
>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues:
| Array<SchemaIssue.Issue>
| undefined
},
items: ReadonlyArray<
[key: PropertyKey, is: IndexSignature]
>,
options?: IterateEagerOptions
) =>
| Effect.Effect<
void,
SchemaIssue.Issue,
any
>
| undefined)
| undefined
parseIndexes) {
const const keyPairs: [
PropertyKey,
IndexSignature
][]
keyPairs = import ArrArr.const empty: <[PropertyKey, IndexSignature]>() => [PropertyKey, IndexSignature][]Creates an empty array.
When to use
Use to create a typed empty array without allocating placeholder elements.
Example (Creating an empty array)
import { Array } from "effect"
const result = Array.empty<number>()
console.log(result) // []
empty<[type PropertyKey =
| string
| number
| symbol
PropertyKey, class IndexSignatureclass IndexSignature {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature]>()
for (let let i: numberi = 0; let i: numberi < const indexCount: numberindexCount; let i: numberi++) {
const const is: IndexSignatureconst is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is = const ast: thisast.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures[let i: numberi]
const const keys: readonly PropertyKey[]keys = function getIndexSignatureKeys(
input: { readonly [x: PropertyKey]: unknown },
parameter: IndexSignatureParameter,
options?: ParseOptions
): ReadonlyArray<PropertyKey>
Returns the object keys that match the index signature parameter schema.
getIndexSignatureKeys(const input: Record<PropertyKey, unknown>input, const is: IndexSignatureconst is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.parameter: IndexSignatureParameterparameter, options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options)
for (let let j: numberj = 0; let j: numberj < const keys: readonly PropertyKey[]keys.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length; let j: numberj++) {
const const key: PropertyKeykey = const keys: readonly PropertyKey[]keys[let j: numberj]
const keyPairs: [
PropertyKey,
IndexSignature
][]
keyPairs.Array<[PropertyKey, IndexSignature]>.push(...items: [PropertyKey, IndexSignature][]): numberAppends new elements to the end of an array, and returns the new length of the array.
push([const key: PropertyKeykey, const is: IndexSignatureconst is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is])
}
}
const const eff:
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
eff = const parseIndexes: (
initialState: {
readonly oinput: Option.Option<unknown>
readonly input: Record<PropertyKey, unknown>
readonly options: ParseOptions
readonly out: Record<PropertyKey, unknown>
issues: Array<SchemaIssue.Issue> | undefined
},
items: ReadonlyArray<
[key: PropertyKey, is: IndexSignature]
>,
options?: IterateEagerOptions
) =>
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
parseIndexes(const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state, const keyPairs: [
PropertyKey,
IndexSignature
][]
keyPairs, const concurrency:
| {
concurrency: number
}
| undefined
concurrency)
if (const eff:
| Effect.Effect<void, SchemaIssue.Issue, any>
| undefined
eff) yield* const eff: Effect.Effect<
void,
SchemaIssue.Issue,
any
>
const eff: {
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; <…;
toString: () => string;
toJSON: () => unknown;
}
eff
}
if (const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state.issues: | [SchemaIssue.Issue, ...SchemaIssue.Issue[]]
| undefined
issues) {
return yield* import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(new import SchemaIssueSchemaIssue.constructor Composite(ast: AST, actual: Option.Option<unknown>, issues: readonly [SchemaIssue.Issue, ...Array<SchemaIssue.Issue>]): SchemaIssue.CompositeRepresents a schema issue that groups multiple child issues under a single schema node.
When to use
Use when you need to walk the issue tree for struct/tuple schemas that collect
all field errors rather than failing on the first.
Details
issues is a non-empty readonly array (at least one child).
actual is Option.some(value) when the input was present, or
Option.none() when absent.
- Formatters flatten
Composite by recursing into each child.
Composite(const ast: thisast, oinput: Option.Some<unknown>(parameter) oinput: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
oinput, const state: {
ast: this
oinput: Option.Some<unknown>
input: Record<PropertyKey, unknown>
out: Record<PropertyKey, unknown>
issues:
| Arr.NonEmptyArray<SchemaIssue.Issue>
| undefined
options: ParseOptions
}
state.issues: [
SchemaIssue.Issue,
...SchemaIssue.Issue[]
]
(property) issues: {
0: SchemaIssue.Issue;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => SchemaIssue.Issue | undefined;
push: (...items: Array<SchemaIssue.Issue>) => number;
concat: { (...items: Array<ConcatArray<SchemaIssue.Issue>>): Array<SchemaIssue.Issue>; (...items: Array<SchemaIssue.Issue | ConcatArray<SchemaIssue.Issue>>): Array<SchemaIssue.Issue> };
join: (separator?: string) => string;
reverse: () => Array<SchemaIssue.Issue>;
shift: () => SchemaIssue.Issue | undefined;
slice: (start?: number, end?: number) => Array<SchemaIssue.Issue>;
sort: (compareFn?: ((a: SchemaIssue.Issue, b: SchemaIssue.Issue) => number) | undefined) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
splice: { (start: number, deleteCount?: number): Array<SchemaIssue.Issue>; (start: number, deleteCount: number, ...items: Array<SchemaIssue.Issue>): Array<SchemaIssue.Issue> };
unshift: (...items: Array<SchemaIssue.Issue>) => number;
indexOf: (searchElement: SchemaIssue.Issue, fromIndex?: number) => number;
lastIndexOf: (searchElement: SchemaIssue.Issue, fromIndex?: number) => number;
every: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): this is S[]; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg…;
some: (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => void, thisArg?: any) => void;
map: (callbackfn: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): Array<S>; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: …;
reduce: { (callbackfn: (previousValue: SchemaIssue.Issue, currentValue: SchemaIssue.Issue, currentIndex: number, array: Array<SchemaIssue.Issue>) => SchemaIssue.Issue): SchemaIssue.Issue; (callbackfn: (previousValue: SchemaIssue.Issue, currentValu…;
reduceRight: { (callbackfn: (previousValue: SchemaIssue.Issue, currentValue: SchemaIssue.Issue, currentIndex: number, array: Array<SchemaIssue.Issue>) => SchemaIssue.Issue): SchemaIssue.Issue; (callbackfn: (previousValue: SchemaIssue.Issue, currentValu…;
find: { (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => unknown, thisArg?:…;
findIndex: (predicate: (value: SchemaIssue.Issue, index: number, obj: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => number;
fill: (value: SchemaIssue.Issue, start?: number, end?: number) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
copyWithin: (target: number, start: number, end?: number) => [SchemaIssue.Issue, ...SchemaIssue.Issue[]];
entries: () => ArrayIterator<[number, SchemaIssue.Issue]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<SchemaIssue.Issue>;
includes: (searchElement: SchemaIssue.Issue, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => SchemaIssue.Issue | undefined;
findLast: { (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => value is S, thisArg?: any): S | undefined; (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisA…;
findLastIndex: (predicate: (value: SchemaIssue.Issue, index: number, array: Array<SchemaIssue.Issue>) => unknown, thisArg?: any) => number;
toReversed: () => Array<SchemaIssue.Issue>;
toSorted: (compareFn?: ((a: SchemaIssue.Issue, b: SchemaIssue.Issue) => number) | undefined) => Array<SchemaIssue.Issue>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<SchemaIssue.Issue>): Array<SchemaIssue.Issue>; (start: number, deleteCount?: number): Array<SchemaIssue.Issue> };
with: (index: number, value: SchemaIssue.Issue) => Array<SchemaIssue.Issue>;
}
issues))
}
if (options: ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options.ParseOptions.propertyOrder?: "none" | "original" | undefinedThe 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.
propertyOrder === "original") {
// preserve input keys order
const const keys: PropertyKey[]keys = (let inputKeys: PropertyKey[] | undefinedinputKeys ?? Reflect.function Reflect.ownKeys(target: object): (string | symbol)[]Returns the string and symbol keys of the own properties of an object. The own properties of an object
are those that are defined directly on that object, and are not inherited from the object's prototype.
ownKeys(const input: Record<PropertyKey, unknown>input)).Array<PropertyKey>.concat(...items: ConcatArray<PropertyKey>[]): PropertyKey[] (+1 overload)Combines two or more arrays.
This method returns a new array without modifying any existing arrays.
concat(const expectedKeys: PropertyKey[]expectedKeys)
const const preserved: Record<
PropertyKey,
unknown
>
preserved: 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, unknown> = {}
for (const const key: PropertyKeykey of const keys: PropertyKey[]keys) {
if (var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.hasOwn(o: object, v: PropertyKey): booleanDetermines whether an object has a property with the specified name.
hasOwn(const out: Record<PropertyKey, unknown>out, const key: PropertyKeykey)) {
import internalRecordinternalRecord.function set<PropertyKey, unknown>(
self: Record<PropertyKey, unknown>,
key: PropertyKey,
value: unknown
): Record<PropertyKey, unknown>
set(const preserved: Record<
PropertyKey,
unknown
>
preserved, const key: PropertyKeykey, const out: Record<PropertyKey, unknown>out[const key: PropertyKeykey])
}
}
return import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(const preserved: Record<
PropertyKey,
unknown
>
preserved)
}
return import OptionOption.const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(const out: Record<PropertyKey, unknown>out)
})
}
private Objects._rebuild(recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined): Objects_rebuild(
recur: (ast: AST) => ASTrecur: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST,
recurParameter: (ast: AST) => ASTrecurParameter: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST,
flipMerge: booleanflipMerge: boolean,
checks: Checks | undefinedchecks: type Checks = readonly [
Check<any>,
...Check<any>[]
]
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.
Checks | undefined,
encodingChecks: Checks | undefinedencodingChecks: type Checks = readonly [
Check<any>,
...Check<any>[]
]
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.
Checks | undefined
): class Objectsclass Objects {
_tag: 'Objects';
propertySignatures: ReadonlyArray<PropertySignature>;
indexSignatures: ReadonlyArray<IndexSignature>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined) => Objects;
flip: (recur: (ast: AST) => AST) => AST;
recur: (recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST) => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects {
const const props: ReadonlyArray<PropertySignature>props = function mapOrSame<PropertySignature>(as: readonly PropertySignature[], f: (a: PropertySignature) => PropertySignature): readonly PropertySignature[] (+1 overload)Maps over the array but will return the original array if no changes occur.
mapOrSame(this.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures, (ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps) => {
const const t: ASTt = recur: (ast: AST) => ASTrecur(ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype)
return const t: ASTt === ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.type: ASTtype ? ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps : new constructor PropertySignature(name: PropertyKey, type: AST): PropertySignaturePropertySignature(ps: PropertySignature(parameter) ps: {
name: PropertyKey;
type: AST;
}
ps.PropertySignature.name: PropertyKeyname, const t: ASTt)
})
const const indexes: ReadonlyArray<IndexSignature>indexes = function mapOrSame<IndexSignature>(as: readonly IndexSignature[], f: (a: IndexSignature) => IndexSignature): readonly IndexSignature[] (+1 overload)Maps over the array but will return the original array if no changes occur.
mapOrSame(this.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures, (is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is) => {
const const p: ASTp = recurParameter: (ast: AST) => ASTrecurParameter(is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.parameter: IndexSignatureParameterparameter)
const const t: ASTt = recur: (ast: AST) => ASTrecur(is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.type: ASTtype)
const const merge: KeyValueCombiner | undefinedmerge = flipMerge: booleanflipMerge ? is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefinedmerge?.KeyValueCombiner.flip(): KeyValueCombinerflip() : is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefinedmerge
return const p: ASTp === is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.parameter: IndexSignatureParameterparameter && const t: ASTt === is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.type: ASTtype && const merge: KeyValueCombiner | undefinedmerge === is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is.IndexSignature.merge: KeyValueCombiner | undefinedmerge
? is: IndexSignature(parameter) is: {
parameter: IndexSignatureParameter;
type: AST;
merge: KeyValueCombiner | undefined;
}
is
: new constructor IndexSignature(parameter: AST, type: AST, merge: KeyValueCombiner | undefined): IndexSignatureRepresents 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
for string keys,
TemplateLiteral
for patterned keys).
type — the value type SchemaAST.
merge — optional
KeyValueCombiner
for handling duplicate keys.
Gotchas
Using Schema.optionalKey on the value type is not allowed for index
signatures (throws at construction); use Schema.optional instead.
IndexSignature(const p: ASTp, const t: ASTt, const merge: KeyValueCombiner | undefinedmerge)
})
return const props: ReadonlyArray<PropertySignature>props === this.Objects.propertySignatures: ReadonlyArray<PropertySignature>propertySignatures && const indexes: ReadonlyArray<IndexSignature>indexes === this.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures && checks: Checks | undefinedchecks === this.Base.checks: Checks | undefinedchecks &&
encodingChecks: Checks | undefinedencodingChecks === this.Objects.encodingChecks: Checks | undefinedencodingChecks
? this
: new constructor Objects(propertySignatures: ReadonlyArray<PropertySignature>, indexSignatures: ReadonlyArray<IndexSignature>, annotations?: Schema.Annotations.Annotations, checks?: Checks, encoding?: Encoding, context?: Context, encodingChecks?: Checks): ObjectsAST node for object-like schemas, including structs and records.
When to use
Use when constructing or inspecting AST nodes for structs or records rather
than array-like schemas.
Details
propertySignatures — named properties with their types (struct fields).
indexSignatures — index signature entries (record patterns), each with
a parameter AST for matching keys and a type AST for values.
An Objects node with no properties and no index signatures performs only a
non-nullish check: it accepts any value except null and undefined,
including primitive values.
Gotchas
Duplicate property names throw at construction time.
Example (Inspecting a struct AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Struct({ name: Schema.String })
const ast = schema.ast
if (SchemaAST.isObjects(ast)) {
for (const ps of ast.propertySignatures) {
console.log(ps.name, ps.type._tag)
}
// "name" "String"
}
Objects(
const props: ReadonlyArray<PropertySignature>props,
const indexes: ReadonlyArray<IndexSignature>indexes,
this.Base.annotations: Schema.Annotations.Annotations | undefinedannotations,
checks: Checks | undefinedchecks,
var undefinedundefined,
this.Base.context: Context | undefinedcontext,
encodingChecks: Checks | undefinedencodingChecks
)
}
/** @internal */
Objects.flip(recur: (ast: AST) => AST): ASTflip(recur: (ast: AST) => ASTrecur: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST): type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST {
return this.Objects._rebuild(recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined): Objects_rebuild(recur: (ast: AST) => ASTrecur, recur: (ast: AST) => ASTrecur, true, this.Objects.encodingChecks: Checks | undefinedencodingChecks, this.Base.checks: Checks | undefinedchecks)
}
/** @internal */
Objects.recur(recur: (ast: AST) => AST, recurParameter?: (ast: AST) => AST): ASTrecur(recur: (ast: AST) => ASTrecur: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST, recurParameter: (ast: AST) => ASTrecurParameter: (ast: ASTast: type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST) => type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST = recur: (ast: AST) => ASTrecur): type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
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
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST {
return this.Objects._rebuild(recur: (ast: AST) => AST, recurParameter: (ast: AST) => AST, flipMerge: boolean, checks: Checks | undefined, encodingChecks: Checks | undefined): Objects_rebuild(recur: (ast: AST) => ASTrecur, recurParameter: (ast: AST) => ASTrecurParameter, false, this.Base.checks: Checks | undefinedchecks, this.Objects.encodingChecks: Checks | undefinedencodingChecks)
}
/** @internal */
Objects.getExpected(): stringgetExpected(): string {
if (this.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 && this.Objects.indexSignatures: ReadonlyArray<IndexSignature>indexSignatures.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 "object | array"
return "object"
}
}