TS
TypeScript Cheatsheet
Core TypeScript syntax - type annotations, interfaces, generics, and the utility types used constantly in real codebases.
Basic types
let x: numberType annotation
let x: string | nullUnion type
let x: "a" | "b"String literal union
let x: number[]Array of numbers
let x: [string, number]Tuple type
let x: unknownType-safe alternative to any
Interfaces & types
interface User { name: string }Define an object shape
type User = { name: string }Type alias (equivalent for objects)
interface Admin extends User {}Extend an interface
name?: stringOptional property
readonly name: stringRead-only property
Generics
function id<T>(x: T): TGeneric function
interface Box<T> { value: T }Generic interface
Array<string>Generic array type
<T extends object>Constrain a generic type
Utility types
Partial<T>All properties optional
Required<T>All properties required
Pick<T, "a" | "b">Select specific properties
Omit<T, "a">Exclude specific properties
Record<string, number>Object type with key/value types