<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]>Derives an isomorphism codec from a schema. The encoded form is the
schema's Iso type — the intermediate representation used for round-tripping.
export function function toCodecIso<S extends Constraint>(
schema: S
): Codec<S["Type"], S["Iso"]>
Derives an isomorphism codec from a schema. The encoded form is the
schema's Iso type — the intermediate representation used for round-tripping.
toCodecIso<function (type parameter) S in toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]>S extends Constraint>(schema: S extends Constraintschema: function (type parameter) S in toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]>S): 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<function (type parameter) S in toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]>S["Type"], function (type parameter) S in toCodecIso<S extends Constraint>(schema: S): Codec<S["Type"], S["Iso"]>S["Iso"]> {
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 toCodecIsoTop: anytoCodecIsoTop(import SchemaASTSchemaAST.const toType: anyStrips all encoding transformations from an AST, returning the decoded
(type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (
Arrays
,
Objects
,
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"
toType(schema: S extends Constraintschema.Constraint["ast"]: SchemaAST.ASTast)))
}