Learn TypeScript – tutorial, cheatsheet & exercises
TypeScript is JavaScript with a type system. You write normal JavaScript and add types such as string, number or your own shapes for objects. The compiler checks that everything fits together, reports errors right in the editor as you type, and in the end produces plain JavaScript.
This way you catch typos, wrong arguments and forgotten null cases before the code runs, and the editor can support you with precise autocompletion and safe renaming. TypeScript is the standard tool for larger web apps, frameworks (Angular, Next.js, NestJS) and Node.js backends. One important thing to know: types only exist at compile time – at runtime everything is JavaScript.
Hello World in TypeScript
const gruss: string = "Hello World!";
console.log(gruss);Like JavaScript, only with the type annotation : string after the name. tsc compiles, node runs the result.
How to get started with TypeScript
TypeScript needs Node.js (nodejs.org, or brew install node). After that you install the compiler per project as a development dependency:
mkdir mein-projekt && cd mein-projekt
npm init -y
npm install --save-dev typescript
npx tsc --versionCreate a configuration file tsconfig.json with sensible defaults (be sure to keep "strict": true enabled):
npx tsc --initWrite a file hallo.ts, compile it with tsc and run the resulting JavaScript with Node:
npx tsc hallo.ts # creates hallo.js
node hallo.jsMore convenient for experimenting: tsx runs TypeScript directly (without type checking), and newer Node.js versions (from 22.18 or 23.6) can even start .ts files themselves by simply stripping the types. Deno and Bun also support TypeScript out of the box.
npx tsx hallo.ts
node hallo.ts # Node.js 22.18+ (only "erasable" syntax, no enums)
npx tsc --noEmit # only check, produce nothing (ideal for CI).ts file.TypeScript learning path
Hello TypeScript & Compiling
Your first program and what the compiler does.
Basic Types & Type Inference
string, number, boolean, arrays, tuples, any and unknown.
Typing Functions
Parameters, return types, optional arguments and function types.
Objects, Interfaces & Type Aliases
Describing the shape of objects – optional, read-only and extensible.
Union & Literal Types
Restricting values to several types or fixed values.
Narrowing, Type Guards & Discriminated Unions
Narrowing types in code and letting the compiler check all cases.
Generics
Reusable functions and classes that work with many types.
Classes in TypeScript
Access modifiers, parameter properties, abstract and implements.
Utility Types
Partial, Pick, Omit, Record & co. – deriving types from types.
Strict Mode & Null Safety
Why strict: true is a must and how to handle null and unknown safely.
Modules, Type Declarations & tsconfig
import type, @types packages, .d.ts files and important compiler options.
keyof, typeof & Mapped Types
Computing types from values and from other types.
Conditional Types, infer & Template Literals
Types with "if-then" logic and strings at the type level.
Advanced Patterns: satisfies, Brands & Overloads
Proven techniques for safe and expressive APIs.
Async, APIs & Runtime Validation
Promise<T>, typed fetch functions and why types do not check data.
At a glance
More about TypeScript
Test & practice
Interactive quiz, timed exam with certificate, and exercises with an editor: