<S extends ConstraintDecoder<unknown>>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Type"], SchemaError>Decodes an unknown input against a schema synchronously, returning an
Exit that is either a Success with the decoded value or a Failure.
When to use
Use when you need to decode unknown input into an Exit and capture schema
mismatches as SchemaError.
Details
Only usable with schemas that have no DecodingServices requirement. Prefer
decodeExit when the input is already typed as the schema's Encoded
type.
Options may be provided either when creating the decoder 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 function function decodeUnknownExit<
S extends ConstraintDecoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Type"], SchemaError>
Decodes an unknown input against a schema synchronously, returning an
Exit that is either a Success with the decoded value or a Failure.
When to use
Use when you need to decode unknown input into an Exit and capture schema
mismatches as SchemaError.
Details
Only usable with schemas that have no DecodingServices requirement. Prefer
decodeExit
when the input is already typed as the schema's Encoded
type.
Options may be provided either when creating the decoder 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.
decodeUnknownExit<function (type parameter) S in decodeUnknownExit<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>S extends interface ConstraintDecoder<out T, out RD = never>Lightweight structural constraint for APIs that need decoder type views but
do not need the full schema protocol.
When to use
Use when you need to preserve a schema's decoded type and decoding services,
but the API does not constrain the encoded type, encoding services, or call
schema methods such as annotate, check, rebuild, make, or
makeEffect.
ConstraintDecoder<unknown>>(schema: S extends ConstraintDecoder<unknown>schema: function (type parameter) S in decodeUnknownExit<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>S, options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) {
const const parser: (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Type"], SchemaIssue.Issue>
parser = import SchemaParserSchemaParser.function decodeUnknownExit<
S extends Schema.ConstraintDecoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit.Exit<S["Type"], SchemaIssue.Issue>
Creates a synchronous decoder for unknown input that reports failure safely
as an Exit.
When to use
Use when you need to decode unknown input synchronously into an Exit whose
failure contains SchemaIssue.Issue.
Details
The returned function produces Exit.Success with the decoded Type.
Schema issues are represented by an Exit.Failure cause containing a
SchemaIssue.Issue.
Gotchas
Because this adapter runs synchronously, async decoding work can produce an
Exit.Failure with a defect cause. When the cause contains both schema
issues and non-schema reasons, all reasons remain in the returned Cause.
decodeUnknownExit(schema: S extends ConstraintDecoder<unknown>schema, options: SchemaAST.ParseOptionsoptions)
return (input: unknowninput: unknown, options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions): import Exit_Exit_.type Exit_.Exit = /*unresolved*/ anyExit<function (type parameter) S in decodeUnknownExit<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Type"], SchemaError>S["Type"], 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> => {
return function fromIssueExit<A>(
exit: Exit_.Exit<A, SchemaIssue.Issue>
): Exit_.Exit<A, SchemaError>
fromIssueExit(const parser: (
input: unknown,
options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Type"], SchemaIssue.Issue>
parser(input: unknowninput, options: SchemaAST.ParseOptionsoptions))
}
}