ReferenceSchema API
s.discriminatedUnion()
One of several object shapes, told apart by a tag: the building block of a page built from sections.
Use it for
- Sections of a page: a hero, a text block, a gallery
- A link that is either internal or external
- Content that comes in variants with different fields
Reference
s.discriminatedUnion(key, ...objects)
schemaOne of several object shapes, told apart by a tag field. The first argument names the field; every object sets it to a different s.literal(). Editors pick the variant from a dropdown and then fill in that variant's fields.
In TypeScript, checking the tag narrows the value to its variant, so a switch over it is exhaustive.
In Val Studio
Examples
Sections of a page
page.val.ts
Rendering it
Page.tsx