Learn TypeScript
Types, interfaces, unions, and functions. Monaco-powered editor with TypeScript autocomplete, run in-browser, and verify—learn by doing.
- Step 1
TypeScript 1: Basic Types
Welcome to TypeScript! TypeScript is JavaScript with **types**. Types tell the compiler what kind of...
Start Lesson - Step 2
TypeScript 2: Typed Arrays
In TypeScript we can type arrays. `string[]` means 'array of strings', and `number[]` means 'array o...
Start Lesson - Step 3
TypeScript 3: Functions with Types
Functions in TypeScript can have types on parameters and return type. `function name(param: type): r...
Start Lesson - Step 4
TypeScript 4: Boolean Type
The `boolean` type can only be `true` or `false`. Perfect for conditionals....
Start Lesson - Step 5
TypeScript 5: Interfaces
**Interfaces** are like blueprints for objects. Once defined, you can use them to type objects....
Start Lesson - Step 6
TypeScript 6: Optional Parameters
Sometimes we want a parameter to be optional. In TypeScript use `?` after the name: `param?: type`...
Start Lesson - Step 7
TypeScript 7: Union Types
A **union type** allows a variable to be one of several types. Use `|`: `string | number` means 'tex...
Start Lesson - Step 8
TypeScript 8: Void Return
Some functions don't return anything (e.g. just log). Use `: void` as the return type....
Start Lesson - Step 9
TypeScript 9: Literal Types
A **literal type** means the value can only be exactly that string or number. `"rojo" | "azul" | "ve...
Start Lesson - Step 10
TypeScript 10: Arrays of Typed Objects
We can create arrays of objects using interfaces. `Persona[]` means 'array of Persona objects'....
Start Lesson