<S extends ConstraintEncoder<unknown>>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: S["Type"],
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Encoded"], SchemaError>Encodes a typed input (the schema's Type) against a schema synchronously,
returning an Exit that is either a Success with the encoded value or a
Failure.
When to use
Use when you need to encode already typed schema values into an Exit and
capture schema mismatches as SchemaError.
Details
Only usable with schemas that have no EncodingServices requirement. For
unknown input use encodeUnknownExit.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
Schema mismatches are represented by a Failure cause containing
SchemaError.
Gotchas
Schema issue fail reasons are wrapped as SchemaError. Defects,
interruptions, and other non-schema reasons remain in the returned Cause,
including when they are mixed with schema issues.
export const const encodeExit: <
S extends ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Type"],
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Encoded"], SchemaError>
Encodes a typed input (the schema's Type) against a schema synchronously,
returning an Exit that is either a Success with the encoded value or a
Failure.
When to use
Use when you need to encode already typed schema values into an Exit and
capture schema mismatches as SchemaError.
Details
Only usable with schemas that have no EncodingServices requirement. For
unknown input use
encodeUnknownExit
.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
Schema mismatches are represented by a Failure cause containing
SchemaError.
Gotchas
Schema issue fail reasons are wrapped as SchemaError. Defects,
interruptions, and other non-schema reasons remain in the returned Cause,
including when they are mixed with schema issues.
encodeExit: <function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>S extends interface ConstraintEncoder<out E, out RE = never>Lightweight structural constraint for APIs that need encoder type views but
do not need the full schema protocol.
When to use
Use when you need to preserve a schema's encoded type and encoding services,
but the API does not constrain the decoded type, decoding services, or call
schema methods such as annotate, check, rebuild, make, or
makeEffect.
ConstraintEncoder<unknown>>(
schema: S extends ConstraintEncoder<unknown>schema: function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>S,
options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions
) => (input: S["Type"]input: function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>S["Type"], options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) => import Exit_Exit_.type Exit_.Exit = /*unresolved*/ anyExit<function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError>S["Encoded"], class SchemaErrorclass SchemaError {
message: string;
toString: () => string;
name: string;
stack: string;
cause: unknown;
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; <…;
toJSON: () => unknown;
_tag: Tag;
issue: SchemaIssue.Issue;
}
Error thrown (or returned as the error channel value) when schema decoding
or encoding fails.
Details
The issue field contains a structured
Issue
tree describing
every validation failure, including the path to the problematic value,
expected types, and actual values received. message renders the issue tree
as a human-readable string.
Use
isSchemaError
to narrow an unknown value to SchemaError.
Example (Catching a SchemaError)
import { Schema } from "effect"
try {
Schema.decodeUnknownSync(Schema.Number)("not a number")
} catch (err) {
if (Schema.isSchemaError(err)) {
console.log(err.message)
// Expected number, actual "not a number"
}
}
SchemaError> = function encodeUnknownExit<
S extends ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Encoded"], SchemaError>
Encodes an unknown input against a schema synchronously, returning an
Exit that is either a Success with the encoded value or a Failure.
When to use
Use when you need to encode unknown input into an Exit and capture schema
mismatches as SchemaError.
Details
Only usable with schemas that have no EncodingServices requirement. Prefer
encodeExit
when the value is already typed as the schema's Type.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
Schema mismatches are represented by a Failure cause containing
SchemaError.
Gotchas
Schema issue fail reasons are wrapped as SchemaError. Defects,
interruptions, and other non-schema reasons remain in the returned Cause,
including when they are mixed with schema issues.
encodeUnknownExit