AI Hints
Home›TypeScript Tutorial›Cheat Sheets and Interviews
TypeScript · Lesson 115 of 120

Cheat Sheet: Basics

The essentials.

⏱ 2 min read▶ Video at 1:31:08🎓 Free
Watch this lesson in the TypeScript courseWatch on YouTube ↗Full TypeScript course

Here are the basics, on one page. Pause whenever you need a reminder.

Cheat Sheet: Basics
From the video: Cheat Sheet: Basics
  • 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.

TopicSyntax
Basicsstring, number, boolean
Arrays / tuplesstring[], [string, number]
Objects{ name: string; phone?: string }
Unions"packing" | "shipped"
Functions(total: number): string
Namestype 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.

CheckUse for
typeof x === "string"basic types
"key" in xobject shapes
x instanceof Errorclasses
switch (x.kind)discriminated unions
const n: never = xexhaustive 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