Hyperlinkv0.8.0-beta.28

Schema

Schema.encodeExitconsteffect/Schema.ts:1942
<S extends ConstraintEncoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
): (
  input: S["Type"],
  options?: SchemaAST.ParseOptions
) => Exit_.Exit<S["Encoded"], SchemaError>

Encodes a typed input (the schema's Type) against a schema synchronously, returning an Exit that is either a Success with the encoded value or a Failure.

When to use

Use when you need to encode already typed schema values into an Exit and capture schema mismatches as SchemaError.

Details

Only usable with schemas that have no EncodingServices requirement. For unknown input use encodeUnknownExit. Options may be provided either when creating the encoder 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.

Source effect/Schema.ts:19424 lines
export const encodeExit: <S extends ConstraintEncoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
) => (input: S["Type"], options?: SchemaAST.ParseOptions) => Exit_.Exit<S["Encoded"], SchemaError> = encodeUnknownExit