<S extends ConstraintDecoder<unknown>>(
schema: S,
options?: SchemaAST.ParseOptions
): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"]Decodes a typed input (the schema's Encoded type) against a schema
synchronously, returning the decoded value or throwing a SchemaError
for schema mismatches.
When to use
Use when you already have input typed as the schema's Encoded type and
want schema mismatches to throw SchemaError synchronously.
Details
For unknown input use decodeUnknownSync.
Only service-free schemas can be decoded synchronously. Options may be
provided either when creating the decoder or when applying it; application
options override creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
export const const decodeSync: <
S extends ConstraintDecoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Encoded"],
options?: SchemaAST.ParseOptions
) => S["Type"]
Decodes a typed input (the schema's Encoded type) against a schema
synchronously, returning the decoded value or throwing a
SchemaError
for schema mismatches.
When to use
Use when you already have input typed as the schema's Encoded type and
want schema mismatches to throw SchemaError synchronously.
Details
For unknown input use decodeUnknownSync.
Only service-free schemas can be decoded synchronously. Options may be
provided either when creating the decoder or when applying it; application
options override creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
decodeSync: <function (type parameter) S in <S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"]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 <S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"]S,
options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions
) => (input: S["Encoded"]input: function (type parameter) S in <S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"]S["Encoded"], options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) => function (type parameter) S in <S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => S["Type"]S["Type"] = function decodeUnknownSync<
S extends ConstraintDecoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => S["Type"]
Decodes an unknown input against a schema synchronously, returning the
decoded value or throwing a
SchemaError
for schema mismatches.
When to use
Use when you need to validate unknown data at a synchronous boundary and want
schema mismatches to throw SchemaError.
Details
For input already typed as the schema's Encoded type use decodeSync.
Only service-free schemas can be decoded synchronously. For alternatives that
do not throw on schema mismatches, see decodeUnknownOption,
decodeUnknownExit, or decodeUnknownEffect. Options may be provided either
when creating the decoder or when applying it; application options override
creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
Example (Decoding with a transformation schema)
import { Schema } from "effect"
const NumberFromString = Schema.NumberFromString
console.log(Schema.decodeUnknownSync(NumberFromString)("42"))
// Output: 42
Schema.decodeUnknownSync(NumberFromString)("not a number")
// throws SchemaError: NumberFromString
// └─ Encoded side transformation failure
// └─ NumberFromString
// └─ Expected a numeric string, actual "not a number"
decodeUnknownSync