TypeScript · Lesson 115 of 120
Cheat Sheet: Basics
The essentials.
Here are the basics, on one page. Pause whenever you need a reminder.

- One page
- The basics
- Pause anytime
Basics cheat sheet
Basic types, arrays, and tuples. Object types with optional and readonly properties. Unions and literal types. Functions with parameter and return types. And interfaces and aliases to name them.
| Topic | Syntax |
|---|---|
| Basics | string, number, boolean |
| Arrays / tuples | string[], [string, number] |
| Objects | { name: string; phone?: string } |
| Unions | "packing" | "shipped" |
| Functions | (total: number): string |
| Names | type X = ..., interface Y {} |
Narrowing cheat sheet
Typeof for basic types. In for object shapes. Instance of for classes. A kind field for discriminated unions. And never, for exhaustive checks.
| Check | Use for |
|---|---|
| typeof x === "string" | basic types |
| "key" in x | object shapes |
| x instanceof Error | classes |
| switch (x.kind) | discriminated unions |
| const n: never = x | exhaustive checks |
Summary
Types, objects, unions, functions, and narrowing, on one page. Next, the advanced cheat sheet.
Key takeaways- Basic types
- Unions
- Narrowing
Next up: Cheat Sheet: Advanced — the essentials