Hyperlinkv0.8.0-beta.28

SchemaIssue

SchemaIssue.getActualfunctioneffect/SchemaIssue.ts:778
(issue: Issue): Option.Option<unknown>

Extracts the actual input value from any Issue variant.

When to use

Use when you need to retrieve an Issue's offending input value for logging or custom error rendering.

Details

  • Returns Option.none() for Pointer and MissingKey (they carry no value).
  • Returns the existing Option for variants that already store actual as Option<unknown> (InvalidType, InvalidValue, Forbidden, Encoding, Composite).
  • Wraps actual with Option.some for variants that store it as plain unknown (AnyOf, UnexpectedKey, OneOf, Filter).

Example (Extracting the actual value)

import { Option, SchemaIssue } from "effect"

const issue = new SchemaIssue.MissingKey(undefined)
console.log(SchemaIssue.getActual(issue))
// { _tag: "None" }
export function getActual(issue: Issue): Option.Option<unknown> {
  switch (issue._tag) {
    case "Pointer":
    case "MissingKey":
      return Option.none()
    case "InvalidType":
    case "InvalidValue":
    case "Forbidden":
    case "Encoding":
    case "Composite":
      return issue.actual
    case "AnyOf":
    case "UnexpectedKey":
    case "OneOf":
    case "Filter":
      return Option.some(issue.actual)
  }
}