HomeChallengesRepsProblemsLeaderboardTake a challenge
TRACK 01

JavaScript + TypeScript

The data problems every frontend job is made of. Graded by running your code, not by reading it.

43 challenges43 free10h of build time43 graded by running your code

Types That Catch Bugs

Working JavaScript with a bug in it. Add the type that would have caught it — graded by the compiler.

  1. Let the compiler lookorders.js has just become orders.ts with strict on. It has three bugs nobody noticed: a typo that makes the total NaN, an id that arrives as a string and finds nothing, and no types at all. Give the compiler enough to find them, then fix what it finds.Beginner · 5 min
  2. Name the shapesOrders 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.Beginner · 8 min
  3. Status is not a stringDelivered orders never leave the "in progress" count. status is a string, so a typo in one comparison compiles happily. Make the typo impossible to write.Beginner · 6 min
  4. Narrow before you touchgetItem takes an id or a name, and promises a MenuItem it does not always have: a cast hides the undefined, so priceLabel("egusi") crashes. Make every caller deal with "not found".Intermediate · 8 min
  5. Trust nothing that arrives as JSONJSON.parse returns any, and that any has spread through the file: parseMenuItem returns it, so a price of "5" sails through. Contain it with unknown and a type guard, and make every function say what it returns.Intermediate · 8 min
  6. Make the impossible unrepresentableA transfer payment with no reference crashed the receipt printer. Payment is one shape with optional fields, so nothing ties a reference to a transfer. Make that payment impossible to build — then add USSD and let the compiler show you the one place that needs it.Advanced · 10 min
  7. Don’t retype the typeThree hand-copied versions of MenuItem have drifted: one lost spicy, two let a caller choose the id, and the update replaces the whole item with the patch. Derive them from MenuItem instead, and protect the menu.Intermediate · 8 min
  8. One function, any itemfindMenuItem, findOrder and findCustomer are the same function three times. Write it once, with a generic that keeps each caller’s own type — and a constraint that refuses anything without an id.Advanced · 10 min

Typed Express

The kitchen’s API. Every request is a stranger until a type says otherwise.

  1. Say what you sendGET /orders returns whatever shape is lying around, and sorts the stored queue in place while it is at it. Make the response type a promise the compiler checks, and return the orders oldest first without changing what is stored.Beginner · 8 min
  2. The order that isn’t thereGET /orders/2 finds nothing, because the id from the URL is a string; GET /orders/99 answers 200 with an empty body; and an unknown route gets a text page. Make a miss say so, in JSON, with a status a client can act on.Beginner · 8 min
  3. Query strings are stringsGET /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.Intermediate · 8 min
  4. The body is unknownPOST /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.Intermediate · 10 min
  5. Routes, controllers and types across filesapp.ts does everything: data, handlers, routes and wiring, in one long file. Split it so each part has one job — handlers in the controller, routes in a router, and app.ts only wiring — without changing a single response.Intermediate · 10 min
  6. Middleware that adds to the requestAnyone can change any order, and the audit line reaches for a vendor nothing ever attached, through (req as any). Write requireVendor: check the key, attach the vendor to the request through Express’s own types, and gate only the routes that change things.Advanced · 10 min