For the complete documentation index, see llms.txt. This page is also available as Markdown.

Union Types (anyOf)

Members that accept more than one type, via anyOf.

When a field must accept values of more than one type, use the anyOf constraint on the any type (see Any). A value is valid if it matches any one of the listed alternatives.

id: { any, anyOf: [string, int] }
---
~ 42      # ✓ matches int
~ abc     # ✓ matches string

A value matching none of the alternatives is rejected:

flag: { any, anyOf: [bool, int] }
---
~ T       #
~ hello   # ✗ matches neither

Constrained and structured alternatives

Each alternative may be a full MemberDef (with constraints) or an object shape, not just a bare type name:

value: { any, anyOf: [ { int, multipleOf: 5 }, { int, multipleOf: 3 } ] }
---
~ 10      # ✓ multiple of 5
~ 9       # ✓ multiple of 3

Guidance

  • Order alternatives from most specific to least specific.

  • Prefer anyOf over a bare any when the set of acceptable types is known — it keeps validation meaningful.

See Also

Last updated

Was this helpful?