Literal

ReferenceSchema API

s.literal()

One exact value. Mostly used as the tag that tells the variants of a discriminated union apart.

Use it for

  • The type field of a section in a page builder

Literal Schema

s.literal(string)

schema

One exact value. Its main use is the tag of each variant in s.discriminatedUnion(). For a choice between a few strings, use s.enum().

Methods

.validate

Custom validation function

Example

Example

TypeScript
s.discriminatedUnion("type", s.object({ type: s.literal("text"), text: s.string() }), s.object({ type: s.literal("image"), image: s.image() }))