Skip to main content
Version: 3.0.0-dev 🔨

Recursive Variants

danger

The pass() function is somewhat broken with fields()

Recursive variants are a wonderful pattern for expressing and evaluating tree and list-like data. The traditional example involves a binary tree and we'll implement a proper one in the next section on generic variants. In the meantime, let's do a binary tree of Animals. An animal tree may not have many real world applications but please bear with me.

Recursive variants are a bit of a deviation from the norm. Wheras up to this point we've defined the variant using a template and inferred the type from there, recursive variants must define their type first and then implement the variant based on that contract. This is a limitation of TypeScript—types may be recursive while values typically cannot.

⏲️ coming soon.