A discriminated union uses a common literal field to label each variant. A switch on that field narrows to the correct shape in each branch. Use an assertNever helper to force compile-time checks that every case is handled.
function assertNever(x: never): never {
throw new Error("unreachable");
}Render each case to a short label and keep branches simple.
Render all result variants and ensure the switch is exhaustive.
type Result = { kind: 'ok'; value: number } | { kind: 'fail'; message: string } | { kind: 'pending' }.assertNever(x: never): never that throws.render(r: Result): string using a switch(r.kind).'OK:' + value, 'FAIL:' + message, or 'PENDING' as appropriate.