HomeChallengesRepsProblemsLeaderboardTake a challenge

The body is unknown

POST /orders trusts whatever JSON arrives: a body with items: "rice" is stored, and a client can set its own id and status. Validate at the door — the body is unknown until a guard proves otherwise.

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

What you build

  • type NewOrder = Omit<Order, "id" | "status" | "placedAt">
  • Write isNewOrder(body: unknown): body is NewOrder
  • On success: assign the id, set status "pending", return 201 with a Location header
  • On failure: return 400 naming the first bad field

Done means

Valid bodies are created with a Location, invalid ones are 400s naming the field, client ids and statuses are ignored, and the body is never cast.

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. A valid body is 201 with a Location+25Failing in a shape callers can read
  2. A missing customer is a 400 naming it+20Failing in a shape callers can read
  3. items: "rice" is a 400+15Failing in a shape callers can read
  4. A client-supplied id or status is ignored+20Failing in a shape callers can read
  5. isNewOrder is a predicate on unknown, and nothing is cast+20TypeScript basics

What it teaches

The rest of Typed Express