effect-io-ai

Package: effect
Module: SchemaAST

SchemaAST.Union

AST node representing a union of schemas.

Details

During parsing, members are tried in order. An internal candidate index narrows which members to try based on the runtime type of the input and discriminant (“sentinel”) fields, making large unions efficient.

Example (Inspecting a union AST)

import { Schema, SchemaAST } from "effect"

const schema = Schema.Union([Schema.String, Schema.Number])
const ast = schema.ast

if (SchemaAST.isUnion(ast)) {
  console.log(ast.types.length) // 2
  console.log(ast.mode)         // "anyOf"
}

See

Signature

declare class Union<A> { constructor(
    types: ReadonlyArray<A>,
    mode: "anyOf" | "oneOf",
    annotations?: Schema.Annotations.Annotations,
    checks?: Checks,
    encoding?: Encoding,
    context?: Context,
    encodingChecks?: Checks
  ) }

Source

Since v3.10.0