HomeChallengesRepsProblemsLeaderboardTake a challenge

Status is not a string

Delivered orders never leave the "in progress" count. status is a string, so a typo in one comparison compiles happily. Make the typo impossible to write.

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

What you build

  • Declare type OrderStatus = "pending" | "cooking" | "ready" | "delivered"
  • Use it on Order and in setStatus
  • Fix the comparison the compiler now flags

Done means

Invalid statuses and impossible comparisons are compile errors, and the count is right.

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 setStatus(order, "done")+25Union types and narrowing
  2. Refuses comparing with "deliverd"+20Union types and narrowing
  3. Order’s status is the OrderStatus union+15Union types and narrowing
  4. countInProgress returns 3+25Union types and narrowing
  5. No as casts+15Union types and narrowing

What it teaches

The rest of Types That Catch Bugs