All challenges
Multiple ChoiceIntermediate 45s

Make illegal states unrepresentable

Which technique best encodes the rule 'a refund is either pending with an amount or completed with a receipt'?
Options
  1. 1A tagged union / sum type where each variant carries only its valid fields
  2. 2A class with every field left nullable alongside a status enum used to track the state
  3. 3Two independent boolean flags, isPending and isCompleted, guarding the refund's fields
  4. 4A plain map of strings to objects keyed by the refund's current status value

Think you can answer under pressure?

Get matched and answer live questions in 3-minute 1v1 battles. Elo ranking, badge tiers and bragging rights on the line.

Play this in a 3-minute battle