All Cheat Sheets

TypeScript Cheat Sheet

TypeScript type system reference — basic types, generics, utility types, type guards, and declaration patterns.

Basic Types

Stringlet s: string = 'hello'
Numberlet n: number = 42
Booleanlet b: boolean = true
Arraylet a: number[] = [1,2,3]
Tuplelet t: [string, number] = ['a', 1]
Anylet x: any = 'anything'
Unknownlet u: unknown = getData()
Neverfunction fail(): never { throw Error() }
Voidfunction log(): void { console.log('hi') }

Interfaces & Types

Interfaceinterface User { name: string; age: number }
Type aliastype ID = string | number
Optionalinterface Cfg { debug?: boolean }
Readonlyinterface Pt { readonly x: number }
Extendinterface Admin extends User { role: string }
Intersectiontype AdminUser = User & { role: string }

Generics

Functionfunction id<T>(x: T): T { return x }
Interfaceinterface Box<T> { value: T }
Constraintfunction len<T extends { length: number }>(x: T)
Defaultinterface Api<T = unknown> { data: T }

Utility Types

Partial<T>Partial<User>All properties optional
Required<T>Required<User>All properties required
Readonly<T>Readonly<User>All properties readonly
Pick<T,K>Pick<User, 'name' | 'age'>Select properties
Omit<T,K>Omit<User, 'password'>Exclude properties
Record<K,V>Record<string, number>Key-value map type
ReturnType<T>ReturnType<typeof fn>Function return type
Parameters<T>Parameters<typeof fn>Function param types

Type Guards

typeofif (typeof x === 'string') { ... }
instanceofif (x instanceof Date) { ... }
inif ('name' in obj) { ... }
Custom guardfunction isUser(x: any): x is User { ... }
Assertionfunction assert(x: any): asserts x is User { }

Enums & Literals

Enumenum Dir { Up, Down, Left, Right }
String enumenum Color { Red = 'RED', Blue = 'BLUE' }
Const enumconst enum Status { Active, Inactive }
Literaltype Theme = 'light' | 'dark'
Template literaltype Event = `on${string}`

Free tools for this

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.