typescript · level 3 check

a typed order checker.

Time to ship a real tool. A shop's orders arrive from the practice server at `https://api.example.com/orders`, and nobody promises they are tidy. Your order checker fetches them, checks every order, and prints a clear report: each good order on one line, each bad one with the reason, then a total.

Nothing from the server is trusted. Each order goes through a smart constructor that returns a `Result`: a quantity must be a whole number above 0 and gets a brand, and delivery is a discriminated union of post and collect, checked by an exhaustive `switch`.

A shipped tool never crashes on bad input. A failed status, a reply that is not JSON, or JSON that is not a list each get a polite message. Fill in each `____`, run it, and the six tests will check good orders, bad orders and a broken server.

Fill in every ____ then run the checks.
  1. 1 It accepts good orders and tidies the postcodeuses: type guards
  2. 2 It rejects quantities that are not whole numbers above 0uses: branded types
  3. 3 It rejects broken records and unknown deliveriesuses: discriminated unions
  4. 4 It reports a server that failsuses: status codes
  5. 5 It copes with a reply that is not JSONuses: try...catch
  6. 6 It refuses JSON that is not a listuses: unknown data

Take as long as you like and try as many times as you want.