@metreeca/blue - v0.10.0
    Preparing search index...

    Function union

    • Creates a union of value shapes.

      Variants are mutually exclusive alternatives (sh:xone): the union is not validated for exclusivity ex-ante, but a state value singles out exactly one variant (sh:xone) at write time while a model placeholder matches at least one by kind (sh:or) at read time. Variant order is preserved deterministically: it drives indexed model keys ({"0": ..., "1": ...}), positional trace-error reporting, and the order of the merged result when an extending shape narrows the union (see UnionShape for the full inheritance contract).

      At extends-time each child variant must narrow exactly one parent variant, so a parent declaring union(reference(Person), reference(Organization)) can be narrowed on either alternative independently. Because matching is by narrowing rather than a precomputed key, parent variants that no child variant can single out (for example two reference variants with the same target shape) cannot be narrowed individually — a child narrowing such a variant is rejected as ambiguous.

      Type Parameters

      Parameters

      • ...variants: V

        The variant shapes

      Returns UnionShape<Variants<V>>

      An immutable union with the specified variants

      const address = optional(union(
      string(),
      reference(PostalAddress)
      ));