toEncoded<S>Type-level representation returned by toEncoded.
export interface interface toEncoded<S extends Constraint>Type-level representation returned by
toEncoded
.
Extracts the encoded-side schema: sets Type to equal the Encoded,
discarding the decoding transformation path.
toEncoded<function (type parameter) S in toEncoded<S extends Constraint>S extends Constraint> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
import SchemaASTSchemaAST.type AST = SchemaAST.Declaration | SchemaAST.Null | SchemaAST.Undefined | SchemaAST.Void | SchemaAST.Never | SchemaAST.Unknown | SchemaAST.Any | SchemaAST.String | SchemaAST.Number | SchemaAST.Boolean | SchemaAST.BigInt | SchemaAST.Symbol | SchemaAST.Literal | SchemaAST.UniqueSymbol | SchemaAST.ObjectKeyword | SchemaAST.Enum | SchemaAST.TemplateLiteral | SchemaAST.Arrays | SchemaAST.Objects | SchemaAST.Union<...> | SchemaAST.SuspendDiscriminated 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,
interface toEncoded<S extends Constraint>Type-level representation returned by
toEncoded
.
Extracts the encoded-side schema: sets Type to equal the Encoded,
discarding the decoding transformation path.
toEncoded<function (type parameter) S in toEncoded<S extends Constraint>S>,
interface ReadonlyArray<T>ReadonlyArray<Constraint>,
function (type parameter) S in toEncoded<S extends Constraint>S["~type.mutability"],
function (type parameter) S in toEncoded<S extends Constraint>S["~type.optionality"],
function (type parameter) S in toEncoded<S extends Constraint>S["~type.constructor.default"],
function (type parameter) S in toEncoded<S extends Constraint>S["~encoded.mutability"],
function (type parameter) S in toEncoded<S extends Constraint>S["~encoded.optionality"]
>
{
readonly "Type": function (type parameter) S in toEncoded<S extends Constraint>S["Encoded"]
readonly "Encoded": function (type parameter) S in toEncoded<S extends Constraint>S["Encoded"]
readonly "DecodingServices": never
readonly "EncodingServices": never
readonly "~type.make.in": function (type parameter) S in toEncoded<S extends Constraint>S["Encoded"]
readonly "~type.make": function (type parameter) S in toEncoded<S extends Constraint>S["Encoded"]
readonly "Iso": function (type parameter) S in toEncoded<S extends Constraint>S["Encoded"]
readonly toEncoded<S extends Constraint>.schema: S extends Constraintschema: function (type parameter) S in toEncoded<S extends Constraint>S
}
interface toEncodedLambda extends Lambda {
<function (type parameter) S in <S extends Constraint>(self: S): toEncoded<S>S extends Constraint>(self: S extends Constraintself: function (type parameter) S in <S extends Constraint>(self: S): toEncoded<S>S): interface toEncoded<S extends Constraint>Type-level representation returned by
toEncoded
.
Extracts the encoded-side schema: sets Type to equal the Encoded,
discarding the decoding transformation path.
toEncoded<function (type parameter) S in <S extends Constraint>(self: S): toEncoded<S>S>
readonly "~lambda.out": this["~lambda.in"] extends Constraint ? interface toEncoded<S extends Constraint>Type-level representation returned by
toEncoded
.
Extracts the encoded-side schema: sets Type to equal the Encoded,
discarding the decoding transformation path.
toEncoded<this["~lambda.in"]> : never
}
/**
* Extracts the encoded-side schema: sets `Type` to equal the `Encoded`,
* discarding the decoding transformation path.
*
* @category transforming
* @since 4.0.0
*/
export const const toEncoded: toEncodedLambdaType-level representation returned by
toEncoded
.
Extracts the encoded-side schema: sets Type to equal the Encoded,
discarding the decoding transformation path.
toEncoded = import Struct_Struct_.const lambda: <toEncodedLambda>(
f: (a: Constraint) => toEncoded<Constraint>
) => toEncodedLambda
Wraps a plain function as a
Lambda
value so it can be used with
When to use
Use to create a typed lambda for struct mapping APIs that need type-level
input and output tracking.
Details
The type parameter L encodes both the input and output types at the type
level, allowing the compiler to track how struct value types change. At
runtime, the returned value is the same function; lambda only adjusts the
type.
Example (Wrapping values in arrays)
import { pipe, Struct } from "effect"
interface AsArray extends Struct.Lambda {
<A>(self: A): Array<A>
readonly "~lambda.out": Array<this["~lambda.in"]>
}
const asArray = Struct.lambda<AsArray>((a) => [a])
const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
console.log(result) // { x: [1], y: ["hello"] }
lambda<toEncodedLambda>((schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema) => 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(import SchemaASTSchemaAST.const toEncoded: anyReturns the encoded (wire-format) AST by flipping and then stripping
encodings.
Details
Equivalent to toType(flip(ast)). This gives you the AST that describes
the shape of the serialized/encoded data.
- Memoized: same input reference → same output reference.
Example (Getting the encoded AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const encodedAst = SchemaAST.toEncoded(schema.ast)
console.log(encodedAst._tag) // "String"
toEncoded(schema: Constraint(parameter) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema.Constraint["ast"]: SchemaAST.ASTast), { schema: Constraint(property) schema: {
ast: SchemaAST.AST;
Type: unknown;
Encoded: unknown;
DecodingServices: unknown;
EncodingServices: unknown;
Iso: unknown;
}
schema }))