TypeScript utility types are built-in mapped types: Partial makes every field optional, Pick/Omit reshape objects, Record builds dictionaries, and ReturnType/Parameters extract function types. Use them to keep DTOs in sync instead of copy-pasting interfaces.
This TypeScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Partial<T>: All properties optional — handy for patches.
- Required<T>: Opposite of Partial.
- Pick<T, K>: Keep keys
KfromT. - Omit<T, K>: Drop keys
K. - Record<K, V>: Object with keys
Kand valuesV. - Readonly<T>: All props readonly (shallow).
- Exclude / Extract: Filter unions.
NonNullable<T>drops null/undefined. - ReturnType / Parameters: From a function type.
Awaited<T>unwraps promises.
Copy-paste examples
DTO helpers for an API patch
Omit server-generated fields on create. Partial for PATCH bodies.
interface User {
id: number;
email: string;
name: string;
role: 'user' | 'admin';
}
export type UserCreate = Omit<User, 'id'>;
export type UserPatch = Partial<Pick<User, 'email' | 'name'>>;
export type UsersById = Record<number, User>;
export type Role = User['role'];Common mistakes
Partialon a nested object and assuming deep fields are optional (it is shallow).Omitof a discriminant and breaking your union.- Re-declaring
ReturnTypehelpers that already exist inlib.es5.d.ts. - Using
Record<string, T>when a union of known keys was safer.
FAQ
- Are utility types runtime? No. They only exist for the checker. You still write the object in JS.
- Pick vs destructuring?
Pickis a type. Destructuring is a value. You often use both: type the rest object asOmit<Props, "className">.
- Can I write my own mapped type? Yes:
{ [K in keyof T]: T[K] | null }. Prefer built-ins until you need something they do not express.
Related TypeScript cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.