HomeChallengesRepsProblemsLeaderboardTake a challenge

Props as a contract

<OrderCard> takes props: any, so nothing stops it being used wrongly — and it crashes on Tunde’s order, because he has no phone number. Give it a props type that says what is required, and render the phone only when there is one.

Beginner8 min on the clock5 graded checks · 100 pointsTyped React
Graded by running your code against real cases.

What you build

  • type OrderCardProps = { order: Order; compact?: boolean }
  • Render the phone only when present
  • Default compact to false
  • Type StatusBadge’s status as OrderStatus

Done means

Required props are required, the status is the union, a card with no phone renders, and nothing is any.

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 <OrderCard /> with no order+20Data flows down
  2. Refuses <StatusBadge status="done" />+20Union types and narrowing
  3. A card with no phone renders+25Data flows down
  4. compact is an optional boolean+20Data flows down
  5. No any and no casts+15TypeScript basics

What it teaches

The rest of Typed React