Overview
Union Schema
Unions in Val allow you to define fields that can be one of several possible types or values. There are two main types of unions:
Literal Unions - Create dropdown fields with a fixed set of string, number, or boolean values. Perfect for variants, sizes, themes, and other predefined options.
Discriminated Unions - Define fields that can be one of several object types, each identified by a discriminator field. Ideal for content blocks with different structures.
Literal Unions
s.union(...s.literal(value))
Union type (one of multiple literal values). Rendered as a dropdown menu in the UI
Methods:
.validate: method
Custom validation function
Example:
Example
Discriminated Union Of Objects
s.union("type", ...s.literal(value))
Discriminated (tagged) union type. Rendered as an object where the first field is the tag type which is rendered as a dropdown in the UI.
Methods:
.validate: method
Custom validation function