HomeChallengesRepsProblemsLeaderboardTake a challenge

Make the impossible unrepresentable

A transfer payment with no reference crashed the receipt printer. Payment is one shape with optional fields, so nothing ties a reference to a transfer. Make that payment impossible to build — then add USSD and let the compiler show you the one place that needs it.

Advanced10 min on the clock5 graded checks · 100 pointsTypes That Catch Bugs
Graded by running your code against real cases.

What you build

  • Model Payment as a discriminated union on kind
  • Give receiptLine a default that assigns p to never
  • Add { kind: "ussd"; code: string } and handle it
  • Leave no optional properties on Payment

Done means

Wrong data for a variant is refused, the switch is exhaustive, and all four kinds print.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. Refuses a transfer with no reference+20Union types and narrowing
  2. Refuses card details on a cash payment+15Union types and narrowing
  3. The default assigns to never+20Union types and narrowing
  4. All four kinds print the right line+30Union types and narrowing
  5. No optional properties on Payment+15Union types and narrowing

What it teaches

The rest of Types That Catch Bugs