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. That is the whole idea. Every JavaScript program is already a TypeScript program. TypeScript adds a layer on top that reads your code before it runs and tells you when something cannot work.

The word static matters. The checker never executes your program. It reads the source, follows which values can reach each operation, and reports the combinations that make no sense.

Let’s see it in action. Here we have a function that wants a string, and a call that passes a number:

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

uppercase(42)

JavaScript would happily run this. It would fail inside the function, because numbers have no toUpperCase() method. You would find out at runtime, maybe in production, maybe from a user.

TypeScript reports the problem before anything runs:

error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

The name: string part is a type annotation. It tells the checker what kind of value name should hold. The checker then compares that promise with every call it can find.

Types do a second job too: they document contracts. Hover over uppercase in your editor and it shows you that the function expects a string. Type name. inside the body and the editor lists string methods. Nobody had to write that documentation by hand.

What TypeScript is not

TypeScript is not a new runtime. Browsers and Node.js run JavaScript, and only JavaScript. Before your code runs, the type annotations get stripped away. The : string disappears and plain JavaScript is left behind.

This has a consequence people miss at first. Since the types are gone at runtime, they cannot inspect a network response, check a form value, or change how JavaScript behaves. A type is a claim about your code, checked while you write it. It is not a guard that runs while the program executes.

So here is the mental model for the whole course:

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

Keep those two sentences in mind. Most confusion with TypeScript comes from mixing them up.

Try this on your own: change uppercase(42) to a valid call and confirm the error goes away. Then think of one value TypeScript cannot know about without a runtime check. A good candidate is anything that comes from JSON.parse().

Lesson completed