HomeChallengesRepsProblemsLeaderboardTake a challenge

Query strings are strings

GET /orders?status=ready&paid=false&limit=2 ignores the query entirely. Type it, and parse each value into the type it stands for — a status in the union, a real boolean, a number with a default — rejecting what does not parse.

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

What you build

  • Type the query as { status?: string; paid?: string; limit?: string }
  • Narrow status to OrderStatus with a type guard
  • Turn paid into a boolean by comparing, and limit into a number defaulting to 20
  • Return 400 for an unknown status or a limit that is not a number

Done means

Each filter parses into its real type, bad values are 400s, and nothing is 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. ?status=ready returns ready orders only+20Union types and narrowing
  2. ?paid=false returns unpaid orders, not all of them+20TypeScript basics
  3. ?limit=2 returns 2, and no limit returns up to 20+20TypeScript basics
  4. An unknown status or a bad limit is a 400+25Failing in a shape callers can read
  5. The query is typed, and nothing is cast+15TypeScript basics

What it teaches

The rest of Typed Express