Start using TypeScript

What TypeScript adds to JavaScript

See TypeScript as JavaScript plus a static type checker, not as a separate runtime or a replacement language.

TypeScript is JavaScript plus a static type checker.

The checker studies your source code before it runs. It tracks which values can reach each operation and reports combinations that do not make sense.

For example:

function uppercase(name: string) {
  return name.toUpperCase()
}

uppercase(42)

JavaScript would try to run this call and fail inside the function. TypeScript reports the number argument before the program starts.

Types also document contracts. An editor can show that uppercase() expects a string and offer string methods while you type.

But TypeScript is not a new runtime. Browsers and Node.js ultimately execute JavaScript. Type annotations disappear from the emitted code, so they cannot inspect a network response or change how JavaScript behaves.

This gives us the main mental model for the course:

  • TypeScript checks what the source code can prove.
  • JavaScript handles the values that exist at runtime.

Exercise: change uppercase(42) to a valid call. Then think of one value TypeScript cannot know without a runtime check.

Lesson completed

Take this course offline

Get every free book, course edition, and software download.

Get the download library →