Model variant objects with a shared discriminant field.
Section: Mapped and Conditional Types
Discriminated union pattern
typescript
typescript
type Success = { kind: "success"; data: string };
type Failure = { kind: "error"; message: string };
type Result = Success | Failure;Explanation
Discriminated unions pair especially well with narrowing in control flow.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Mapped and Conditional Types