TypeScript Cheatsheet - Type Types & Generics Reference
All the TypeScript types and syntax you need for daily development — from basic types to advanced generics, organized by category, ready to copy into your code.
Back to LanguagesBasic Types 8
let name: string = "John"String type
let age: number = 30Number type
let isActive: boolean = trueBoolean type
let items: string[] = ["a", "b"]Array type
let tuple: [string, number] = ["a", 1]Tuple type
let value: any = "anything"Any type (use with caution)
let value: unknown = "safe"Unknown type (safe)
let value: neverNever type
Interfaces & Types 5
interface User { name: string; age: number }Define an interface
type User = { name: string; age: number }Type alias
interface Admin extends User { role: string }Interface inheritance
type Status = "active" | "inactive"Union type
type Result = string | null | undefinedNullable type
Generics 4
function identity<T>(arg: T): T { return arg }Generic function
interface Container<T> { value: T }Generic interface
type Pair<T, U> = [T, U]Multi-parameter generics
function getFirst<T>(arr: T[]): TGeneric constraint
Utility Types 6
Partial<User>All properties optional
Required<User>All properties required
Readonly<User>All properties readonly
Pick<User, "name" | "age">Pick a subset of properties
Omit<User, "age">Omit specific properties
Record<string, number>Key-value pair type
💡 Tips
- unknown is safer than any — it requires type checking or type assertion before use.
- interface supports declaration merging, type does not; type supports unions and mapped types.
- as const makes object properties literal types, e.g., { role: "admin" as const }.
- The satisfies operator (TS 4.9+) validates types while preserving the inferred type.