Hyperlinkv0.8.0-beta.28

SchemaGetter

SchemaGetter.requiredfunctioneffect/SchemaGetter.ts:369
<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<
  T,
  E
>

Creates a getter that fails with MissingKey if the input is absent (Option.None).

When to use

Use when you need a schema getter to require a struct field in the encoded input and report a missing key error when it is absent.

Details

  • When input is None, fails with SchemaIssue.MissingKey.
  • When input is Some, passes it through unchanged.
  • Optional annotations customize the error message for the missing key.

Example (Defining a required struct field)

import { SchemaGetter } from "effect"

const mustExist = SchemaGetter.required<string>()
constructorsonNonewithDefault
export function required<T, E extends T = T>(annotations?: Schema.Annotations.Key<T>): Getter<T, E> {
  return onNone(() => Effect.fail(new SchemaIssue.MissingKey(annotations)))
}