let x: number = 10 Number type
let s: string = "hello" String type
let b: boolean = true Boolean type
let arr: number[] = [1, 2, 3] Array type
let tuple: [string, number] Tuple type (fixed length & types)
let x: any Any type (opt out of type checking)
let x: unknown Unknown type (safer than any)
let x: never Never type (unreachable code)
let x: void Void type (no return value)
let x: null | undefined Null and undefined types
type ID = string | number Union type
type Point = { x: number; y: number } Type alias for object
const x = "hello" as const Const assertion (literal type)
interface User {
name: string;
age: number;
} Interface declaration
interface User {
email?: string;
} Optional property
interface User {
readonly id: number;
} Readonly property
interface Admin extends User {
role: string;
} Interface inheritance
interface Fn {
(x: number): string;
} Callable interface
interface Dict {
[key: string]: number;
} Index signature
interface A extends B, C {} Multiple inheritance
function identity<T>(arg: T): T {
return arg;
} Generic function
interface Box<T> {
value: T;
} Generic interface
class Container<T> {
constructor(public value: T) {}
} Generic class
function fn<T extends HasLength>(x: T) Generic constraint
function fn<T, K extends keyof T>(obj: T, key: K) keyof constraint
type Pair<T, U = T> = [T, U] Generic with default type
function fn<T extends string | number>(x: T) Union constraint
Partial<User> Make all properties optional
Required<User> Make all properties required
Readonly<User> Make all properties readonly
Pick<User, "name" | "age"> Pick subset of properties
Omit<User, "password"> Omit specific properties
Record<string, number> Object type with key/value types
ReturnType<typeof fn> Extract function return type
Parameters<typeof fn> Extract function parameter types
Awaited<Promise<string>> Unwrap Promise type
NonNullable<string | null> Remove null/undefined from type
Extract<A | B | C, A | B> Extract matching union members
Exclude<A | B | C, A> Remove matching union members
if (typeof x === "string") typeof guard
if (x instanceof Date) instanceof guard
if ("name" in obj) in operator guard
function isUser(x: any): x is User {
return "name" in x;
} Custom type predicate
x as string Type assertion
x satisfies Type Satisfies operator (TS 4.9+)
enum Direction {
Up,
Down,
Left,
Right
} Numeric enum (0, 1, 2, 3)
enum Status {
Active = "ACTIVE",
Inactive = "INACTIVE"
} String enum
const enum Color { Red, Green, Blue } Const enum (inlined at compile)
type Keys = keyof User Get union of object keys
type Val = User["name"] Indexed access type
type Mapped = {
[K in keyof T]: boolean
} Mapped type
type IsString<T> = T extends string
? "yes" : "no" Conditional type
type Flatten<T> = T extends Array<infer U>
? U : T infer keyword
type Literal = "a" | "b" | "c" String literal union type
declare module "lib" {
export function fn(): void;
} Module declaration (ambient)
// @ts-ignore Suppress next-line TS error
// @ts-expect-error Expect error on next line
Free Online TypeScript Cheatsheet
A searchable TypeScript type system reference. Covers basic types, interfaces, generics, utility types, type guards, enums, and advanced patterns like conditional types and mapped types.
About this cheatsheet
A comprehensive TypeScript cheatsheet focused on the type system and patterns.
- 55+ TypeScript type patterns
- 7 categories from basics to advanced
- All utility types covered
- Generic patterns and constraints
- One-click copy to clipboard
- Covers TypeScript 5.x features
100% free. No signup required. No data collected or sent anywhere.