TypeScript

JavaScript with types, for catching mistakes before your code runs.

TypeScript is JavaScript with optional static types, checked by a compiler before the code runs. Your editor can catch mistakes and suggest completions as you type, and because all valid JavaScript is valid TypeScript, you can adopt it one file at a time.

  • Intermediate
  • 13 lessons
  • 8 exercises
  • Runs in your browser
Not started yet0 of 8 exercises solved
Start lesson 1

Lessons

  1. Hello, TypeScript!Write and run your first TypeScript file. You will see how types are added on top of ordinary JavaScript and how the code is compiled to run.
  2. Basic TypesLearn TypeScript's basic types, including the extras it adds to JavaScript such as tuples, enums, `unknown`, `never` and `void`. You will also see how TypeScript infers types so you do not have to write them everywhere.1 exercise
  3. Interfaces & Type AliasesInterfaces and type aliases both let you give a name to the shape of an object. This lesson shows how to use each and the small differences between them.2 exercises
  4. Typed FunctionsLearn how to type function parameters and return values. This is where types help most day to day, because the compiler checks every call before you run anything.1 exercise
  5. ClassesLearn how TypeScript extends JavaScript classes with access modifiers (`public`, `private`, `protected`, `readonly`) and parameter properties, a shorthand for declaring fields in the constructor.1 exercise
  6. GenericsGenerics let one function or class work with many types while staying type-safe. You will learn to read and write type parameters like `<T>`.1 exercise
  7. Utility TypesTypeScript includes built-in utility types such as Partial, Pick and Omit that build new types from existing ones. Using them saves you from writing and maintaining near-duplicate type definitions.1 exercise
  8. Async TypeScriptLearn how async functions are typed: they return `Promise<T>`, and `await` gives you the `T`. You will also see how to handle errors safely, since a caught error has the type `unknown`.
  9. Mini Project: Typed CLI ToolBuild a small typed command-line tool that queries a public API. It brings together generics, interfaces, async/await and the Result pattern in one program.
  10. Narrowing & Type GuardsLearn how TypeScript narrows a union type such as string | number to a single type by following your if statements and checks. This is how you work safely with values that can be more than one type.1 exercise
  11. Conditional, Mapped & Template Literal TypesLearn conditional types, mapped types, infer and template literal types. These are the tools used to build utility types like Partial and ReturnType, and they help you read library type definitions.
  12. Modules, Declaration Files & tsconfigLearn how tsconfig.json controls which files the compiler checks, how strict it is and what JavaScript it outputs. Many confusing build problems come down to these settings.
  13. TypeScript CheatsheetThe type system on one page — annotations, interfaces, generics, utility types.

Install it on your own computer

Install TypeScript with npm (you need Node.js first). For quick experiments, ts-node or tsx can run .ts files directly without a separate compile step. You do not need this to follow the lessons: the examples run in your browser.

Bash
# Install Node.js from nodejs.org first
# Then install TypeScript and ts-node:
npm install -g typescript ts-node

# Verify:
tsc --version
ts-node --version

What people build with TypeScript

Learn the basics first, then pick up these tools when a project needs them.

Practical uses

  • Build large web applications with safer refactoring
  • Create typed APIs and backend services
  • Publish reliable JavaScript libraries
  • Share domain models across frontend and backend

Projects to try

  1. Typed budgeting app
  2. REST client SDK
  3. Realtime team chat
  4. Type-safe full-stack issue tracker

Common tools and packages

TypeScript ESLintZodtRPCNestJSPrismaVitestPlaywrighttsup

Well-known software

Visual Studio CodeSlackNotionLinearDenoAngular