TypeScript Cheat Sheet - Every Type and Pattern You Need (2026)

TypeScript Cheat Sheet - Every Type and Pattern You Need (2026)

DevTools Store

TypeScript Cheat Sheet (2026)

Every TypeScript type, utility, and pattern in one page. Bookmark this.

Basic Types

let str: string = 'hello';
let num: number = 42;
let bool: boolean = true;
let arr: number[] = [1, 2, 3];
let tuple: [string, number] = ['hello', 42];
let any: any = 'anything';
let unknown: unknown = 'safe';
let nullable: string | null = null;
let undef: string | undefined = undefined;

Interfaces and Types

interface User {
  id: number;
  name: string;
  email: string;
  role?: 'admin' | 'user'; // optional + union
  readonly createdAt: Date;
}

type Status = 'active' | 'inactive' | 'pending';
type ID = string | number;
type UserRecord = Record<string, User>;

Generics

function identity<T>(arg: T): T { return arg; }
function first<T>(arr: T[]): T | undefined { return arr[0]; }

interface ApiResponse<T> {
  data: T;
  status: number;
  message: string;
}

// Constraint
type WithId = { id: number };
function findById<T extends WithId>(items: T[], id: number): T | undefined {
  return items.find(item => item.id === id);
}

Utility Types

Partial<T>      // All properties optional
Required<T>     // All properties required
Readonly<T>     // All properties readonly
Record<K, V>    // Object with keys K and values V
Pick<T, K>      // Subset of T with keys K
Omit<T, K>      // T without keys K
Exclude<U, E>   // Members of U not in E
Extract<U, E>   // Members of U in E
ReturnType<F>   // Return type of function F
Parameters<F>   // Parameter types as tuple
Awaited<T>      // Unwrap Promise type

Common Patterns

// Narrowing
function process(value: string | number) {
  if (typeof value === 'string') { /* string */ }
  if (typeof value === 'number') { /* number */ }
}

// Type guard
function isUser(value: unknown): value is User {
  return typeof value === 'object' && value !== null && 'name' in value;
}

// Satisfies (TS 4.9+)
const config = { port: 3000, host: 'localhost' } satisfies Record<string, string | number>;

// Const assertion
const ROLES = ['admin', 'user', 'mod'] as const;
type Role = typeof ROLES[number]; // 'admin' | 'user' | 'mod'

Get 7 production-ready developer products (Next.js SaaS boilerplate, React hooks, Tailwind components, and more). Pay what you want:

Get the Complete Bundle

Report Page