Type Inspector — TypeScript

Inspect TypeScript types: 15 levels of primitives, unions, literals and inference. The clearest beginner TypeScript game around.

What you learn in this game

In TypeScript, you can declare a variable's type using the : type syntax. TypeScript will check whether the given value matches the declared type.

An array in TypeScript can be declared with type[] or Array<type>. Every element must match the specified type.

A union type lets a variable accept more than one data type. It's written with a | (pipe) between the allowed types.

An object type in TypeScript describes the shape of an object, including the property names and their types. The given object must have matching properties.

A function in TypeScript can declare its parameter types and its return value type. TypeScript checks whether the returned value matches the declared type.

TypeScript has two syntaxes for arrays: string[] and Array<string>. They're identical. Array<T> uses generic syntax.

What the levels ask

  1. This code is valid. What type does TypeScript infer for the variable x?
  2. What happens to this code?
  3. What happens to this code?
  4. What is the type of arr?
  5. What happens?
  6. Is this code valid?
  7. What happens?
  8. Is this code valid?
  9. What happens?
  10. What happens?
  11. What is the type of items?
  12. What happens?

And more, 15 levels in all.