All Cheat Sheets
TypeScript Cheat Sheet
TypeScript type system reference — basic types, generics, utility types, type guards, and declaration patterns.
Basic Types
String
let s: string = 'hello'Number
let n: number = 42Boolean
let b: boolean = trueArray
let a: number[] = [1,2,3]Tuple
let t: [string, number] = ['a', 1]Any
let x: any = 'anything'Unknown
let u: unknown = getData()Never
function fail(): never { throw Error() }Void
function log(): void { console.log('hi') }Interfaces & Types
Interface
interface User { name: string; age: number }Type alias
type ID = string | numberOptional
interface Cfg { debug?: boolean }Readonly
interface Pt { readonly x: number }Extend
interface Admin extends User { role: string }Intersection
type AdminUser = User & { role: string }Generics
Function
function id<T>(x: T): T { return x }Interface
interface Box<T> { value: T }Constraint
function len<T extends { length: number }>(x: T)Default
interface Api<T = unknown> { data: T }Utility Types
Partial<T>
Partial<User>All properties optionalRequired<T>
Required<User>All properties requiredReadonly<T>
Readonly<User>All properties readonlyPick<T,K>
Pick<User, 'name' | 'age'>Select propertiesOmit<T,K>
Omit<User, 'password'>Exclude propertiesRecord<K,V>
Record<string, number>Key-value map typeReturnType<T>
ReturnType<typeof fn>Function return typeParameters<T>
Parameters<typeof fn>Function param typesType Guards
typeof
if (typeof x === 'string') { ... }instanceof
if (x instanceof Date) { ... }in
if ('name' in obj) { ... }Custom guard
function isUser(x: any): x is User { ... }Assertion
function assert(x: any): asserts x is User { }Enums & Literals
Enum
enum Dir { Up, Down, Left, Right }String enum
enum Color { Red = 'RED', Blue = 'BLUE' }Const enum
const enum Status { Active, Inactive }Literal
type Theme = 'light' | 'dark'Template literal
type Event = `on${string}`