0 of 6 problems solved0%
6 of 6

Exhaustive Result Renderer

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.

Your Task

Render all result variants and ensure the switch is exhaustive.

  • Define type Result = { kind: 'ok'; value: number } | { kind: 'fail'; message: string } | { kind: 'pending' }.
  • Provide function assertNever(x: never): never that throws.
  • Write function render(r: Result): string using a switch(r.kind).
  • Return 'OK:' + value, 'FAIL:' + message, or 'PENDING' as appropriate.