Schema.Codec<PrimitiveTree, PrimitiveTree, never, never>Schema for PrimitiveTree.
When to use
Use to validate recursive annotation metadata trees whose leaves are null,
number, boolean, bigint, symbol, or string.
export const const $PrimitiveTree: Schema.Codec<PrimitiveTree>const $PrimitiveTree: {
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
Rebuild: Codec<T, E, RD, RE>;
Type: T;
Iso: Iso;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<PrimitiveTree, any>) => Schema.Codec<PrimitiveTree, PrimitiveTree, never, never>;
annotateKey: (annotations: Schema.Annotations.Key<PrimitiveTree>) => Schema.Codec<PrimitiveTree, PrimitiveTree, never, never>;
check: (checks_0: SchemaAST.Check<PrimitiveTree>, ...checks: Array<SchemaAST.Check<PrimitiveTree>>) => Schema.Codec<PrimitiveTree, PrimitiveTree, never, never>;
rebuild: (ast: SchemaAST.AST) => Schema.Codec<PrimitiveTree, PrimitiveTree, never, never>;
make: (input: unknown, options?: MakeOptions) => SchemaRepresentation.PrimitiveTree;
makeOption: (input: unknown, options?: MakeOptions) => Option_.Option<SchemaRepresentation.PrimitiveTree>;
makeEffect: (input: unknown, options?: MakeOptions) => Effect.Effect<SchemaRepresentation.PrimitiveTree, 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 for
PrimitiveTree
.
When to use
Use to validate recursive annotation metadata trees whose leaves are null,
number, boolean, bigint, symbol, or string.
$PrimitiveTree: import SchemaSchema.interface Codec<out T, out E = T, out RD = never, out RE = never>Namespace of type-level helpers for
Codec
.
A schema that tracks the decoded type T, the encoded type E, and the
Effect services required during decoding (RD) and encoding (RE).
Details
Use Codec<T, E, RD, RE> when you need to preserve full type information
about a schema — both what it decodes to and what it serializes from/to.
Most concrete schemas produced by this module implement Codec.
For APIs that only need one direction, prefer the narrower views:
Decoder
<T, RD> — decode-only
Encoder
<E, RE> — encode-only
Schema
<T> — type-only (no encoded representation)
Example (Accepting a codec that decodes to number from string)
import { Schema } from "effect"
declare function serialize<T>(codec: Schema.Codec<T, string>): string
serialize(Schema.NumberFromString) // ok — decodes number, encoded as string
Codec<type PrimitiveTree =
| string
| number
| bigint
| boolean
| symbol
| Schema.TreeRecord<
| string
| number
| bigint
| boolean
| symbol
| null
>
| readonly Schema.Tree<
| string
| number
| bigint
| boolean
| symbol
| null
>[]
| null
A tree of primitive values used to serialize annotations to JSON.
PrimitiveTree> = import SchemaSchema.function Tree<S extends Constraint>(
node: S
): Union<
readonly [
S,
$Array<
suspend<
Codec<
Tree<S["Type"]>,
Tree<S["Encoded"]>,
S["DecodingServices"],
S["EncodingServices"]
>
>
>,
$Record<
String,
suspend<
Codec<
Tree<S["Type"]>,
Tree<S["Encoded"]>,
S["DecodingServices"],
S["EncodingServices"]
>
>
>
]
>
Creates a recursive schema for a
Tree
of values described by node.
The resulting schema accepts a single node value, an array of trees, or an
object whose values are trees.
Tree(
import SchemaSchema.function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([
import SchemaSchema.const Null: Nullconst Null: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<null, readonly []>) => Schema.Null;
annotateKey: (annotations: Schema.Annotations.Key<null>) => Schema.Null;
check: (checks_0: SchemaAST.Check<null>, ...checks: Array<SchemaAST.Check<null>>) => Schema.Null;
rebuild: (ast: SchemaAST.Null) => Schema.Null;
make: (input: null, options?: MakeOptions) => null;
makeOption: (input: null, options?: MakeOptions) => Option_.Option<null>;
makeEffect: (input: null, options?: MakeOptions) => Effect.Effect<null, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Null
.
Schema for the null literal. Validates that the input is strictly null.
Null,
import SchemaSchema.const Number: Numberconst Number: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<number, readonly []>) => Schema.Number;
annotateKey: (annotations: Schema.Annotations.Key<number>) => Schema.Number;
check: (checks_0: SchemaAST.Check<number>, ...checks: Array<SchemaAST.Check<number>>) => Schema.Number;
rebuild: (ast: SchemaAST.Number) => Schema.Number;
make: (input: number, options?: MakeOptions) => number;
makeOption: (input: number, options?: MakeOptions) => Option_.Option<number>;
makeEffect: (input: number, options?: MakeOptions) => Effect.Effect<number, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Number
.
Schema for number values, including NaN, Infinity, and -Infinity.
Details
Default JSON serializer:
- Finite numbers are serialized as numbers.
- Non-finite values are serialized as strings (
"NaN", "Infinity", "-Infinity").
Number, // allows NaN, Infinity, -Infinity
import SchemaSchema.const Boolean: Booleanconst Boolean: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<boolean, readonly []>) => Schema.Boolean;
annotateKey: (annotations: Schema.Annotations.Key<boolean>) => Schema.Boolean;
check: (checks_0: SchemaAST.Check<boolean>, ...checks: Array<SchemaAST.Check<boolean>>) => Schema.Boolean;
rebuild: (ast: SchemaAST.Boolean) => Schema.Boolean;
make: (input: boolean, options?: MakeOptions) => boolean;
makeOption: (input: boolean, options?: MakeOptions) => Option_.Option<boolean>;
makeEffect: (input: boolean, options?: MakeOptions) => Effect.Effect<boolean, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Boolean
.
Schema for boolean values. Validates that the input is typeof "boolean".
When to use
Use to validate values that are already JavaScript booleans.
Boolean,
import SchemaSchema.const BigInt: BigIntconst BigInt: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<bigint, readonly []>) => Schema.BigInt;
annotateKey: (annotations: Schema.Annotations.Key<bigint>) => Schema.BigInt;
check: (checks_0: SchemaAST.Check<bigint>, ...checks: Array<SchemaAST.Check<bigint>>) => Schema.BigInt;
rebuild: (ast: SchemaAST.BigInt) => Schema.BigInt;
make: (input: bigint, options?: MakeOptions) => bigint;
makeOption: (input: bigint, options?: MakeOptions) => Option_.Option<bigint>;
makeEffect: (input: bigint, options?: MakeOptions) => Effect.Effect<bigint, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
BigInt
.
Schema for bigint values. Validates that the input is typeof "bigint".
When to use
Use when the input is already a bigint and the schema should validate and
preserve bigint values without parsing from another representation.
BigInt,
import SchemaSchema.const Symbol: Symbolconst Symbol: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<symbol, readonly []>) => Schema.Symbol;
annotateKey: (annotations: Schema.Annotations.Key<symbol>) => Schema.Symbol;
check: (checks_0: SchemaAST.Check<symbol>, ...checks: Array<SchemaAST.Check<symbol>>) => Schema.Symbol;
rebuild: (ast: SchemaAST.Symbol) => Schema.Symbol;
make: (input: symbol, options?: MakeOptions) => symbol;
makeOption: (input: symbol, options?: MakeOptions) => Option_.Option<symbol>;
makeEffect: (input: symbol, options?: MakeOptions) => Effect.Effect<symbol, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
Symbol
.
Schema for symbol values. Validates that the input is typeof "symbol".
Symbol,
import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String
])
)