Hyperlinkv0.8.0-beta.28

SchemaParser

SchemaParser.encodeUnknownResultfunctioneffect/SchemaParser.ts:806
<S extends Schema.ConstraintEncoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
): (
  input: unknown,
  options?: SchemaAST.ParseOptions
) => Result.Result<S["Encoded"], SchemaIssue.Issue>

Creates an encoder for unknown input that reports failure safely as a Result.

When to use

Use when encoding values from an unknown or dynamically typed boundary synchronously, and you want SchemaIssue.Issue failures returned as Result data.

Details

The returned function produces Result.succeed with the schema's Encoded value on success or Result.fail with a SchemaIssue.Issue on encoding failure.

Gotchas

This adapter runs synchronously. Causes made entirely of schema issues become Result.fail, but causes that contain defects, interruptions, or asynchronous work at this synchronous boundary throw instead.

export function encodeUnknownResult<S extends Schema.ConstraintEncoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
): (input: unknown, options?: SchemaAST.ParseOptions) => Result.Result<S["Encoded"], SchemaIssue.Issue> {
  return asResult(encodeUnknownEffect(schema, options))
}
Referenced by 2 symbols