<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"export function 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<function (type parameter) S in decodeUnknownSync<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, 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 decodeUnknownSync<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => S["Type"]S, options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) {
const const parser: (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaError,
S["DecodingServices"]
>
parser = 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(schema: S extends ConstraintDecoder<unknown>schema, options: SchemaAST.ParseOptionsoptions)
return (input: unknowninput: unknown, options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions): function (type parameter) S in decodeUnknownSync<S extends ConstraintDecoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: unknown, options?: SchemaAST.ParseOptions) => S["Type"]S["Type"] => {
return function runSchemaErrorSync<A>(
self: Effect.Effect<A, SchemaError>
): A
runSchemaErrorSync(const parser: (
input: unknown,
options?: SchemaAST.ParseOptions
) => Effect.Effect<
S["Type"],
SchemaError,
S["DecodingServices"]
>
parser(input: unknowninput, options: SchemaAST.ParseOptionsoptions))
}
}