Complete worked example
typescript
type Count = { kind: "ready"; count: number } | { kind: "failed"; message: string };
function describe(value: Count): string {
switch (value.kind) {
case "ready": return String(value.count);
case "failed": return value.message;
default: { const impossible: never = value; return impossible; }
}
}- Reasoning
- Each branch gets only the payload justified by its kind; never checks completeness.