Error Detective — TypeScript

Find the type error: 12 levels reading TS errors and fixing annotations. A TypeScript debugging game that trains your eye for type mismatches.

What you learn in this game

In TypeScript, every variable has a type. If you declare let x: string, then x can only be filled with a string, not a number or another type.

An array in TypeScript can be given an element type. number[] means every element must be a number, string[] means they must all be strings.

The generic type Array<T> means the same as T[]. Array<number> = number[], Array<string> = string[]. Every element must match the type T.

With strictNullChecks (the default in modern TypeScript), null and undefined must be stated explicitly using a union type.

If a variable has a union type (say string | number), you have to narrow the type before accessing a property that only exists on one of the types.

A readonly property can only be set when the object is created. After that, its value can't be changed. To "change" it, make a new object.

What the levels ask

  1. Find the line that contains a type error.
  2. Find the line that contains a type error.
  3. Find the line that contains a type error.
  4. Find the line that contains a type error.
  5. Find the line that contains a type error.
  6. Find the line that contains a type error.
  7. Find the line that contains a type error.
  8. Find the line that contains a type error.
  9. Find the line that contains a type error.
  10. Find the line that contains a type error.
  11. Find the line that contains a type error.
  12. Find the line that contains a type error.