HomeChallengesRepsProblemsLeaderboardTake a challenge

Name the shapes

Orders are plain objects and nothing says what one must contain, so an order for a customer with no landmark prints "(near undefined)". Give the customer and the order a type each, so a malformed order cannot be written down — and handle the optional landmark.

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

What you build

  • Define Customer: a name, an optional phone, and an address with an area and an optional landmark
  • Define Order: an id, a customer and items: MenuItem[]
  • Type describeOrder(order: Order): string
  • Include the landmark only when there is one

Done means

Malformed orders are refused by the compiler, Order’s items are MenuItem[], and both descriptions print exactly.

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 an order with no customer+20TypeScript basics
  2. Refuses a string price inside an order+20TypeScript basics
  3. Refuses an address with no area+15TypeScript basics
  4. An order holds MenuItem[]+15TypeScript basics
  5. Both orders are described exactly+30TypeScript basics

What it teaches

The rest of Types That Catch Bugs