TypeScript: Your first TypeScript program

TypeScript is a programming language that compiles to JavaScript.

You’ve heard it right.

Browsers can only execute JavaScript, and you can’t tell Chrome “run this TypeScript code”.

So you need a compilation step before being able to run TypeScript.

Most of the time, this compilation step is done by tools you already use, like Vite or Next.js or Astro or whatever. Maybe your server runtime too, if you use Bun.

You write TypeScript in .ts files.

Your first TypeScript file can easily be “just JavaScript”:

const greet = () => {
  console.log('Hello world!')


TypeScript is a superset of JavaScript.

This means that in theory any JavaScript is valid TypeScript.

But of course we want it to do more, otherwise … why use it at all?

And the thing you do with TypeScript is adding types.

Lessons in this unit:

0: Introduction
1: ▶︎ Your first TypeScript program
2: Types
3: Typing functions
4: The editor helps you with type errors
5: Running TypeScript code
6: Valid types
7: Type aliases and interfaces
8: Union types
9: Typing arrays with generics
10: The DX of editing TypeScript
11: There's more...