<S extends ConstraintEncoder<unknown>>(
schema: S,
options?: SchemaAST.ParseOptions
): (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"]Encodes a typed input (the schema's Type) against a schema synchronously,
throwing a SchemaError for schema mismatches.
When to use
Use when you already have a value typed as the schema's Type and want
schema mismatches to throw SchemaError synchronously.
Details
For unknown input use encodeUnknownSync.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
export const const encodeSync: <
S extends ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
) => (
input: S["Type"],
options?: SchemaAST.ParseOptions
) => S["Encoded"]
Encodes a typed input (the schema's Type) against a schema synchronously,
throwing a
SchemaError
for schema mismatches.
When to use
Use when you already have a value typed as the schema's Type and want
schema mismatches to throw SchemaError synchronously.
Details
For unknown input use
encodeUnknownSync
.
Options may be provided either when creating the encoder or when applying it;
application options override creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
encodeSync: <function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"]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) => S["Encoded"]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) => S["Encoded"]S["Type"], options: SchemaAST.ParseOptionsoptions?: import SchemaASTSchemaAST.ParseOptions) => function (type parameter) S in <S extends ConstraintEncoder<unknown>>(schema: S, options?: SchemaAST.ParseOptions): (input: S["Type"], options?: SchemaAST.ParseOptions) => S["Encoded"]S["Encoded"] = function encodeUnknownSync<
S extends ConstraintEncoder<unknown>
>(
schema: S,
options?: SchemaAST.ParseOptions
): (
input: unknown,
options?: SchemaAST.ParseOptions
) => S["Encoded"]
Encodes an unknown input against a schema synchronously, throwing a
SchemaError
for schema mismatches.
When to use
Use when you need to serialize unknown data at a synchronous boundary and
want schema mismatches to throw SchemaError.
Details
For alternatives that do not throw on schema mismatches, see
encodeUnknownOption
,
encodeUnknownExit
, or
encodeUnknownEffect
. For values already typed as the schema's Type
use
encodeSync
. Options may be provided either when creating the
encoder or when applying it; application options override creation options.
Gotchas
Non-schema failures may throw a runtime failure instead of SchemaError.
encodeUnknownSync