A discriminated union gives each variant a literal field such as kind. Checking that field makes the matching variant’s fields safe to access.
The demo alternates between success/data and error/message. When adding a new variant, check that every handling branch is covered.
When to use
Use it for responses or state machines whose fields depend on a variant.