Hyperlinkv0.8.0-beta.28

SchemaParser

SchemaParser.decodePromisefunctioneffect/SchemaParser.ts:357
<S extends Schema.ConstraintDecoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
): (
  input: S["Encoded"],
  options?: SchemaAST.ParseOptions
) => Promise<S["Type"]>

Creates a Promise-based decoder for input already typed as the schema's Encoded type.

When to use

Use when you already have input typed as the schema's Encoded type and need decoding to return a JavaScript Promise.

Details

The returned function resolves with the decoded Type on success and rejects with an Error whose cause is a SchemaIssue.Issue on decoding failure.

Gotchas

Causes that contain defects, interruptions, or other non-schema reasons reject with an Error whose cause is the underlying Cause.

export function decodePromise<S extends Schema.ConstraintDecoder<unknown>>(
  schema: S,
  options?: SchemaAST.ParseOptions
): (input: S["Encoded"], options?: SchemaAST.ParseOptions) => Promise<S["Type"]> {
  return asPromise(decodeEffect(schema, options))
}