Option<A>Schema for Option<A> values.
export interface interface Option<A extends Constraint>Schema for Option<A> values.
Type-level representation returned by
Option
.
Option<function (type parameter) A in Option<A extends Constraint>A extends Constraint> extends
interface declareConstructor<T, E, TypeParameters extends ReadonlyArray<Constraint>, Iso = T>Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
Type-level representation returned by
declareConstructor
.
declareConstructor<
import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) A in Option<A extends Constraint>A["Type"]>,
import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) A in Option<A extends Constraint>A["Encoded"]>,
readonly [function (type parameter) A in Option<A extends Constraint>A],
type OptionIso<A extends Constraint> =
| {
readonly _tag: "None"
}
| {
readonly _tag: "Some"
readonly value: A["Iso"]
}
Iso representation used for Option schemas.
Details
None is represented as { _tag: "None" }, while Some is represented as
{ _tag: "Some", value } using the wrapped schema's Iso type.
OptionIso<function (type parameter) A in Option<A extends Constraint>A>
>
{
readonly "Rebuild": interface Option<A extends Constraint>Schema for Option<A> values.
Type-level representation returned by
Option
.
Option<function (type parameter) A in Option<A extends Constraint>A>
readonly Option<A extends Constraint>.value: A extends Constraintvalue: function (type parameter) A in Option<A extends Constraint>A
}
/**
* Iso representation used for `Option` schemas.
*
* **Details**
*
* `None` is represented as `{ _tag: "None" }`, while `Some` is represented as
* `{ _tag: "Some", value }` using the wrapped schema's `Iso` type.
*
* @category Option
* @since 4.0.0
*/
export type type OptionIso<A extends Constraint> =
| {
readonly _tag: "None"
}
| {
readonly _tag: "Some"
readonly value: A["Iso"]
}
Iso representation used for Option schemas.
Details
None is represented as { _tag: "None" }, while Some is represented as
{ _tag: "Some", value } using the wrapped schema's Iso type.
OptionIso<function (type parameter) A in type OptionIso<A extends Constraint>A extends Constraint> =
| { readonly _tag: "None"_tag: "None" }
| { readonly _tag: "Some"_tag: "Some"; readonly value: A["Iso"]value: function (type parameter) A in type OptionIso<A extends Constraint>A["Iso"] }
/**
* Schema for `Option<A>` values.
*
* @category Option
* @since 3.10.0
*/
export function function Option<A extends Constraint>(
value: A
): Option<A>
Schema for Option<A> values.
Option<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A extends Constraint>(value: A extends Constraintvalue: function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A): interface Option<A extends Constraint>Schema for Option<A> values.
Type-level representation returned by
Option
.
Option<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A> {
const const schema: declareConstructor<
Option_.Option<A["Type"]>,
Option_.Option<A["Encoded"]>,
readonly [A],
OptionIso<A>
>
const schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Option_.Option<A['Type']>, readonly [A]>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
annotateKey: (annotations: Annotations.Key<Option_.Option<A['Type']>>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
check: (checks_0: SchemaAST.Check<Option_.Option<A['Type']>>, ...checks: Array<SchemaAST.Check<Option_.Option<A['Type']>>>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
make: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Option_.Option<A['Type']>;
makeOption: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Option_.Option<Option_.Option<A['Type']>>;
makeEffect: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Effect.Effect<Option_.Option<A['Type']>, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema = function declareConstructor<
T,
E = T,
Iso = T
>(): <
TypeParameters extends ReadonlyArray<Constraint>
>(
typeParameters: TypeParameters,
run: (typeParameters: {
readonly [K in keyof TypeParameters]: Codec<
TypeParameters[K]["Type"],
TypeParameters[K]["Encoded"]
>
}) => (
u: unknown,
self: SchemaAST.Declaration,
options: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue>,
annotations?: Annotations.Declaration<
T,
TypeParameters
>
) => declareConstructor<T, E, TypeParameters, Iso>
Creates a schema for a parametric type (a generic container such as
Array<A>, Option<A>, etc.) by accepting a list of type-parameter schemas
and a decoder factory.
When to use
Use when you are defining a schema for a generic container whose validation
depends on one or more type-parameter schemas.
Details
The outer call declareConstructor<T, E, Iso>() fixes the decoded type T,
the encoded type E, and the optional iso type. The inner call receives:
typeParameters — the concrete schemas for each type variable
run — a factory that, given resolved codecs for each type parameter,
returns a parsing function (u, ast, options) => Effect<T, Issue>
annotations — optional metadata
declareConstructor<
import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A["Type"]>,
import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A["Encoded"]>,
type OptionIso<A extends Constraint> =
| {
readonly _tag: "None"
}
| {
readonly _tag: "Some"
readonly value: A["Iso"]
}
Iso representation used for Option schemas.
Details
None is represented as { _tag: "None" }, while Some is represented as
{ _tag: "Some", value } using the wrapped schema's Iso type.
OptionIso<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A>
>()(
[value: A extends Constraintvalue],
([value: Codec<
A["Type"],
A["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<A['Type'], any>) => Codec<A['Type'], A['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<A['Type']>) => Codec<A['Type'], A['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<A['Type']>, ...checks: Array<SchemaAST.Check<A['Type']>>) => Codec<A['Type'], A['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<A['Type'], A['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => A['Type'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<A['Type']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<A['Type'], SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value]) => (input: unknowninput, ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, options: SchemaAST.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 (import Option_Option_.isOption(input: unknowninput)) {
if (import Option_Option_.isNone(input: Option_.Option<unknown>input)) {
return import EffectEffect.succeedNone
}
return import EffectEffect.mapBothEager(
import SchemaParserSchemaParser.function decodeUnknownEffect<
S extends Schema.Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaIssue.Issue,
S["DecodingServices"]
>
Creates an effectful decoder for unknown input.
When to use
Use when you need to decode untyped boundary input in an Effect whose
failure channel is SchemaIssue.Issue, while preserving transformations
and service requirements.
Details
The returned function succeeds with the schema's decoded Type or fails with a
SchemaIssue.Issue. Decoding service requirements are preserved in the returned
Effect. Parse options may be provided when creating the decoder and overridden
when applying it.
decodeUnknownEffect(value: Codec<
A["Type"],
A["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<A['Type'], any>) => Codec<A['Type'], A['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<A['Type']>) => Codec<A['Type'], A['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<A['Type']>, ...checks: Array<SchemaAST.Check<A['Type']>>) => Codec<A['Type'], A['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<A['Type'], A['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => A['Type'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<A['Type']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<A['Type'], SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value)(input: Option_.Some<unknown>(parameter) input: {
_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;
}
input.value, options: SchemaAST.ParseOptions(parameter) options: {
errors: "first" | "all" | undefined;
onExcessProperty: "ignore" | "error" | "preserve" | undefined;
propertyOrder: "none" | "original" | undefined;
disableChecks: boolean | undefined;
concurrency: number | "unbounded" | undefined;
}
options),
{
onSuccess: <A>(value: A) => Option<A>onSuccess: import Option_Option_.some,
onFailure: (issue: any) => SchemaIssue.CompositeonFailure: (issue: SchemaIssue.Issueissue) =>
new import SchemaIssueSchemaIssue.constructor Composite(ast: SchemaAST.AST, actual: StandardJSONSchemaV1<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(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, import Option_Option_.some(input: Option_.Some<unknown>(parameter) input: {
_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;
}
input), [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(["value"], issue: SchemaIssue.Issueissue)])
}
)
}
return import EffectEffect.fail(new import SchemaIssueSchemaIssue.constructor InvalidType(ast: SchemaAST.AST, actual: StandardJSONSchemaV1<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(ast: SchemaAST.Declaration(parameter) ast: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, import Option_Option_.some(input: unknowninput)))
},
{
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "effect/Option"
},
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.Option(?)`,
type Type: stringType: `Option.Option<?>`,
importDeclaration?: string | undefinedimportDeclaration: `import * as Option from "effect/Option"`
},
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "Option",
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.toCodec?: ((typeParameters: readonly [Codec<A["Encoded"], A["Encoded"], never, never>]) => SchemaAST.Link) | undefinedtoCodec: ([value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
(parameter) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<A['Encoded'], any>) => Codec<A['Encoded'], A['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<A['Encoded']>) => Codec<A['Encoded'], A['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<A['Encoded']>, ...checks: Array<SchemaAST.Check<A['Encoded']>>) => Codec<A['Encoded'], A['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<A['Encoded'], A['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => A['Encoded'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<A['Encoded']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<A['Encoded'], SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value]) =>
function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<import Option_Option_.type Option_.Option = /*unresolved*/ anyOption<function (type parameter) A in Option<A extends Constraint>(value: A): Option<A>A["Encoded"]>>()(
function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([
function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({ _tag: Literal<"Some">(property) _tag: {
literal: L;
transform: (to: L2) => decodeTo<Literal<L2>, Literal<'Some'>, never, never>;
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<'Some', readonly []>) => Literal<'Some'>;
annotateKey: (annotations: Annotations.Key<'Some'>) => Literal<'Some'>;
check: (checks_0: SchemaAST.Check<'Some'>, ...checks: Array<SchemaAST.Check<'Some'>>) => Literal<'Some'>;
rebuild: (ast: SchemaAST.Literal) => Literal<'Some'>;
make: (input: 'Some', options?: MakeOptions) => 'Some';
makeOption: (input: 'Some', options?: MakeOptions) => Option_.Option<'Some'>;
makeEffect: (input: 'Some', options?: MakeOptions) => Effect.Effect<'Some', SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
_tag: function Literal<
L extends SchemaAST.LiteralValue
>(literal: L): Literal<L>
Creates a schema for a single literal value (string, number, bigint, boolean, or null).
Example (Defining a string literal)
import { Schema } from "effect"
const schema = Schema.Literal("hello")
// Type: Schema.Literal<"hello">
Literal("Some"), value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
(property) value: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Annotations.Bottom<A['Encoded'], any>) => Codec<A['Encoded'], A['Encoded'], never, never>;
annotateKey: (annotations: Annotations.Key<A['Encoded']>) => Codec<A['Encoded'], A['Encoded'], never, never>;
check: (checks_0: SchemaAST.Check<A['Encoded']>, ...checks: Array<SchemaAST.Check<A['Encoded']>>) => Codec<A['Encoded'], A['Encoded'], never, never>;
rebuild: (ast: SchemaAST.AST) => Codec<A['Encoded'], A['Encoded'], never, never>;
make: (input: unknown, options?: MakeOptions) => A['Encoded'];
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<A['Encoded']>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<A['Encoded'], SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value }),
function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({ _tag: Literal<"None">(property) _tag: {
literal: L;
transform: (to: L2) => decodeTo<Literal<L2>, Literal<'None'>, never, never>;
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<'None', readonly []>) => Literal<'None'>;
annotateKey: (annotations: Annotations.Key<'None'>) => Literal<'None'>;
check: (checks_0: SchemaAST.Check<'None'>, ...checks: Array<SchemaAST.Check<'None'>>) => Literal<'None'>;
rebuild: (ast: SchemaAST.Literal) => Literal<'None'>;
make: (input: 'None', options?: MakeOptions) => 'None';
makeOption: (input: 'None', options?: MakeOptions) => Option_.Option<'None'>;
makeEffect: (input: 'None', options?: MakeOptions) => Effect.Effect<'None', SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
_tag: function Literal<
L extends SchemaAST.LiteralValue
>(literal: L): Literal<L>
Creates a schema for a single literal value (string, number, bigint, boolean, or null).
Example (Defining a string literal)
import { Schema } from "effect"
const schema = Schema.Literal("hello")
// Type: Schema.Literal<"hello">
Literal("None") })
]),
import SchemaTransformationSchemaTransformation.function transform<T, E>(options: {
readonly decode: (input: E) => T
readonly encode: (input: T) => E
}): Transformation<T, E>
Creates a Transformation from pure (sync, infallible) decode and encode
functions.
When to use
Use when you need an infallible schema transformation that does not require
Effect services.
Details
- Each function receives the input and returns the output directly.
- Skips
None inputs (missing keys) — functions are only called on present values.
- Does not allocate Effects internally; uses optimized sync path.
Example (Converting between cents and dollars)
import { Schema, SchemaTransformation } from "effect"
const CentsFromDollars = Schema.Number.pipe(
Schema.decodeTo(
Schema.Number,
SchemaTransformation.transform({
decode: (dollars) => dollars * 100,
encode: (cents) => cents / 100
})
)
)
transform({
decode: (
input: NoInfer<
| Struct.ReadonlySide<
{
readonly _tag: Literal<"Some">
readonly value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: Literal<"None">
},
"Type"
>
>
) => any
decode: (e: NoInfer<
| Struct.ReadonlySide<
{
readonly _tag: Literal<"Some">
readonly value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: Literal<"None">
},
"Type"
>
>
e) => e: | Struct.ReadonlySide<
{
readonly _tag: Literal<"Some">
readonly value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: Literal<"None">
},
"Type"
>
e._tag: "None" | "Some"_tag === "None" ? import Option_Option_.none() : import Option_Option_.some(e: Struct.ReadonlySide<
{
readonly _tag: Literal<"Some">
readonly value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
},
"Type"
>
(parameter) e: {
_tag: 'Some';
value: A['Encoded'];
}
e.value: A["Encoded"]value),
encode: (input: any) => NoInfer<
| Struct.ReadonlySide<
{
readonly _tag: Literal<"Some">
readonly value: Codec<
A["Encoded"],
A["Encoded"],
never,
never
>
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: Literal<"None">
},
"Type"
>
>
encode: (o: Option_.Option<A["Encoded"]>o) => (import Option_Option_.isSome(o: Option_.Option<A["Encoded"]>o) ? { _tag: "None" | "Some"_tag: "Some", value: anyvalue: o: Option_.Some<A["Encoded"]>(parameter) o: {
_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;
}
o.value } as type const = {
readonly _tag: "Some";
readonly value: any;
}
const : { _tag: "None" | "Some"_tag: "None" } as type const = {
readonly _tag: "None";
}
const)
})
),
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.toArbitrary?: Annotations.ToArbitrary.Declaration<Option_.Option<A["Type"]>, readonly [A]> | undefinedtoArbitrary: ([value: Annotations.ToArbitrary.TypeParameter<
A["Type"]
>
(parameter) value: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
value]) => (fc: typeof FastCheckfc, ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx) => {
const const terminal: anyterminal = fc: typeof FastCheckfc.constant(import Option_Option_.none())
const const arbitrary: anyarbitrary = fc: typeof FastCheckfc.oneof(
const terminal: anyterminal,
value: Annotations.ToArbitrary.TypeParameter<
A["Type"]
>
(parameter) value: {
arbitrary: FastCheck.Arbitrary<T>;
terminal: FastCheck.Arbitrary<T> | undefined;
}
value.Annotations.ToArbitrary.TypeParameter<T>.arbitrary: FastCheck.Arbitrary<T>arbitrary.map(import Option_Option_.some)
)
return function withRecursion<unknown>(
fc: typeof FastCheck,
ctx: Annotations.ToArbitrary.Context,
terminal:
| FastCheck.Arbitrary<unknown>
| undefined,
arbitrary: FastCheck.Arbitrary<unknown>
): {
arbitrary: any
terminal: any
}
withRecursion(fc: typeof FastCheckfc, ctx: Annotations.ToArbitrary.Context(parameter) ctx: {
constraint: ToArbitrary.GenerationConstraint | undefined;
recursion: ToArbitrary.Recursion | undefined;
}
ctx, const terminal: anyterminal, const arbitrary: anyarbitrary)
},
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.toEquivalence?: Annotations.ToEquivalence.Declaration<Option_.Option<A["Type"]>, readonly [A]> | undefinedtoEquivalence: ([value: Equivalence.Equivalence<A["Type"]>value]) => import Option_Option_.makeEquivalence(value: Equivalence.Equivalence<A["Type"]>value),
Annotations.Declaration<Option_.Option<A["Type"]>, readonly [A]>.toFormatter?: Annotations.ToFormatter.Declaration<Option_.Option<A["Type"]>, readonly [A]> | undefinedtoFormatter: ([value: Formatter<A["Type"], string>value]) =>
import Option_Option_.match({
onNone: () => stringonNone: () => "none()",
onSome: (t: any) => stringonSome: (t: anyt) => `some(${value: Formatter<A["Type"], string>value(t: anyt)})`
})
}
)
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(const schema: declareConstructor<
Option_.Option<A["Type"]>,
Option_.Option<A["Encoded"]>,
readonly [A],
OptionIso<A>
>
const schema: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<Option_.Option<A['Type']>, readonly [A]>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
annotateKey: (annotations: Annotations.Key<Option_.Option<A['Type']>>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
check: (checks_0: SchemaAST.Check<Option_.Option<A['Type']>>, ...checks: Array<SchemaAST.Check<Option_.Option<A['Type']>>>) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
rebuild: (ast: SchemaAST.Declaration) => declareConstructor<Option_.Option<A['Type']>, Option_.Option<A['Encoded']>, readonly [A], OptionIso<A>>;
make: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Option_.Option<A['Type']>;
makeOption: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Option_.Option<Option_.Option<A['Type']>>;
makeEffect: (input: Option_.Option<A['Type']>, options?: MakeOptions) => Effect.Effect<Option_.Option<A['Type']>, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
schema.Bottom<Option_.Option<A["Type"]>, Option_.Option<A["Encoded"]>, A["DecodingServices"], A["EncodingServices"], Declaration, declareConstructor<Option_.Option<A["Type"]>, Option_.Option<A["Encoded"]>, readonly [A], OptionIso<...>>, ... 8 more ..., "required">["ast"]: SchemaAST.Declaration(property) Bottom<Option_.Option<A["Type"]>, Option_.Option<A["Encoded"]>, A["DecodingServices"], A["EncodingServices"], Declaration, declareConstructor<Option_.Option<A["Type"]>, Option_.Option<A["Encoded"]>, readonly [A], OptionIso<...>>, ... 8 more ..., "required">["ast"]: {
_tag: 'Declaration';
typeParameters: ReadonlyArray<AST>;
run: (typeParameters: ReadonlyArray<AST>) => (input: unknown, self: Declaration, options: ParseOptions) => Effect.Effect<any, SchemaIssue.Issue, any>;
encodingChecks: Checks | undefined;
getParser: () => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Declaration;
recur: (recur: (ast: AST) => AST) => Declaration;
flip: (recur: (ast: AST) => AST) => Declaration;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
ast, { value: A extends Constraintvalue })
}