
Programming cheat sheet
TypeScript Utility Types and Patterns Cheat Sheet
A filterable reference for Partial, Pick, Omit, Record and friends, with narrowing, satisfies, generics, and a strict tsconfig baseline.
A working reference for the TypeScript features you reach for every week. Look up any built-in utility type in a filterable table, then see them applied to one realistic model. Learn narrowing with discriminated unions and exhaustive checks, when to use satisfies versus a type annotation, how to write constrained generics, mapped and conditional types, and which tsconfig flags catch the most bugs. Includes a step-by-step typed fetch helper, two quizzes, and a type-safety review checklist. Every sample compiles under strict mode.
A living reference, not a download. Buy once and every update is included. It's currently on version 1, and you read it in your account, always current.
- Sections
- 7
- Code samples
- 5
- Tables
- 3
Outcomes
What you will be able to do
- Pick the right utility type without opening the docs
- Model API results and state with discriminated unions that the compiler checks
- Use satisfies, as const, and generics with confidence
- Turn on the tsconfig flags that prevent real production bugs
- Replace any with unknown and narrow safely
Is this for you?
Made for
- JavaScript developers moving to TypeScript
- React and Next.js developers who want stricter, cleaner types
- Developers who can read TypeScript but struggle to write generics and mapped types
Probably not for
- Complete beginners who have never written JavaScript
- Anyone looking for advanced type-level programming puzzles
Free preview
Read a piece before you buy
TypeScript's built-in utility types and a handful of patterns cover most of what real codebases need. This sheet lists each one with a one-line meaning and a runnable example, then shows the narrowing, generics, and tsconfig settings that catch the most bugs.
Use the filter box on the tables to find a utility fast. Every code sample compiles on current TypeScript with strict enabled.
Utility types at a glance
| Partial<T> | Every property becomes optional | Partial<User> |
| Required<T> | Every property becomes required | Required<Config> |
| Readonly<T> | Every property becomes readonly | Readonly<State> |
| Pick<T, K> | Only the listed keys | Pick<User, "id" | "name"> |
| Omit<T, K> | Everything except the listed keys | Omit<User, "password"> |
| Record<K, V> | An object type with keys K and values V | Record<string, number> |
| Exclude<U, X> | Remove members of a union | Exclude<"a" | "b", "a"> // "b" |
| Extract<U, X> | Keep only matching members of a union | Extract<"a" | 1, string> // "a" |
| NonNullable<T> | Remove null and undefined | NonNullable<string | null> |
| ReturnType<F> | The type a function returns | ReturnType<typeof fetchUser> |
| Parameters<F> | A tuple of a function's parameter types | Parameters<typeof fetchUser> |
| Awaited<T> | Unwrap a Promise, recursively | Awaited<Promise<string>> |
| InstanceType<C> | The type of instances of a class | InstanceType<typeof Map> |
| Uppercase<S> | Uppercase a string literal type (also Lowercase, Capitalize, Uncapitalize) | Uppercase<"id"> // "ID" |
14 of 14 rows
interface User {
id: string
name: string
email: string
role: "admin" | "member"
}
// A form that edits some fields and leaves the rest alone
type UserPatch = Partial<Pick<User, "name" | "email">>
// Safe to send to the browser
type PublicUser = Omit<User, "email">
// One label for every role, checked for completeness
const roleLabels: Record<User["role"], string> = {
admin: "Administrator",
member: "Member",
}
// Derive types from functions instead of rewriting them
async function loadUser(id: string) {
return { id, name: "Ada", role: "admin" as const }
}
type LoadedUser = Awaited<ReturnType<typeof loadUser>>The utilities you will use every week, applied to one model.
Questions, answered
Which TypeScript version is this written for?
Current TypeScript with strict mode enabled. The satisfies operator needs TypeScript 4.9 or newer.
Does it cover React types?
It focuses on core language features that apply everywhere, including React projects.
Can I copy the code into my project?
Yes. The samples are meant to be copied and adapted.
A clear reference, ready when you need it.
Purchase unlocks the complete guide in your account, with every future update included. You'll create or sign in to your account at checkout so your access stays attached to you.