<S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (
input: S["Encoded"],
options?: SchemaAST.ParseOptions
) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>Decodes a typed input (the schema's Encoded type) against a schema,
returning an Effect that succeeds with the decoded value or fails with a
SchemaError.
When to use
Use when you need to decode input already typed as the schema's Encoded
type in an Effect whose failure channel is SchemaError.
Details
For unknown input use decodeUnknownEffect.
Options may be provided either when creating the decoder or when applying it;
application options override creation options.
export const const decodeEffect: <
S extends Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Encoded"],
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaError,
S["DecodingServices"]
>
Decodes a typed input (the schema's Encoded type) against a schema,
returning an Effect that succeeds with the decoded value or fails with a
When to use
Use when you need to decode input already typed as the schema's Encoded
type in an Effect whose failure channel is SchemaError.
Details
For unknown input use
decodeUnknownEffect
.
Options may be provided either when creating the decoder or when applying it;
application options override creation options.
decodeEffect: <function (type parameter) S in <S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>S extends Constraint>(
schema: S extends Constraintschema: function (type parameter) S in <S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>S,
options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions
) => (
input: S["Encoded"]input: function (type parameter) S in <S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>S["Encoded"],
options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions
) => import EffectEffect.type Effect.Effect = /*unresolved*/ anyEffect<function (type parameter) S in <S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>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, function (type parameter) S in <S extends Constraint>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Effect.Effect<S["Type"], SchemaError, S["DecodingServices"]>S["DecodingServices"]> = function decodeUnknownEffect<
S extends Constraint
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaError,
S["DecodingServices"]
>
Decodes an unknown input against a schema, returning an Effect that
succeeds with the decoded value or fails with a
SchemaError
.
When to use
Use when you need to decode unknown input in an Effect whose failure
channel is SchemaError.
Details
Prefer
decodeEffect
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.
decodeUnknownEffect