TypeScript Utility Types Cheat Sheet: Pick, Omit, Partial and More
Practical examples of TypeScript Partial, Required, Pick, Omit, Record, ReturnType, Awaited, Extract, and Exclude.
TechSilo
Technology writer & developer
TypeScript utility types help transform existing type definitions without copying their fields. They operate at compile time, so they do not validate API responses or alter JavaScript behavior at runtime.
Start with a shared model:
type User = {
id: string;
name: string;
email: string;
active: boolean;
};Transform object properties
| Utility | Meaning | Example |
| --- | --- | --- |
| Partial | All properties become optional | Partial |
| Required | All properties become required | Required |
| Readonly | Properties become readonly in the type system | Readonly |
| Pick | Keep selected keys | Pick |
| Omit | Remove selected keys | Omit |
| Record | Map keys to a value type | Record |
type CreateUser = Pick<User, 'name' | 'email'>;
type UserUpdate = Partial<Omit<User, 'id'>>;
type UserSummary = Readonly<Pick<User, 'id' | 'name'>>;
const counts: Record<'success' | 'failure', number> = {
success: 2,
failure: 0,
};Readonly is enforced by TypeScript's type checker; it does not deep-freeze the runtime object.
Extract useful types from functions
function makeConfig(port: number, debug = false) {
return { port, debug };
}
type Config = ReturnType<typeof makeConfig>;
type ConfigArgs = Parameters<typeof makeConfig>;Config describes the returned object, while ConfigArgs is the parameter tuple. For constructors, ConstructorParameters and InstanceType provide related transformations.
Working with promises
async function loadNames(): Promise<string[]> {
return ['Ada', 'Lin'];
}
type Names = Awaited<ReturnType<typeof loadNames>>;
// string[]Awaited recursively unwraps promise-like types. That makes it useful when an API function returns nested asynchronous values.
Filter union members
type ResponseState = 'idle' | 'loading' | 'success' | 'error';
type FinalState = Extract<ResponseState, 'success' | 'error'>;
type ActiveState = Exclude<ResponseState, 'idle'>;Extract keeps members assignable to the filter; Exclude removes them. Both are conditional-type helpers.
Null handling
type MaybeName = string | null | undefined;
type Name = NonNullable<MaybeName>; // stringNonNullable removes null and undefined from a type, but it does not prevent those values arriving at runtime.
Common pitfalls
- Assuming utility types validate external JSON. They cannot; use runtime schema checks for untrusted data.
- Using Partial for every update. Some fields must be present together; model those constraints explicitly.
- Forgetting optional property semantics. foo?: string and foo: string | undefined are not always interchangeable.
- Assuming Omit removes an object's property. It changes the static type, not the runtime value.
- Using wide Record types. Prefer known keys and unknown where appropriate.
Build utility types around clear domain models, not just to avoid writing a few lines. For type-narrowing errors, see [Troubleshooting TypeScript Value Spreading](/blog/troubleshooting-typescript-any-type-spreading-msif3rsg).
Want to put this into practice?
Explore TechSilo's free developer tools for practical utilities you can use directly in your browser.
Related blog posts
CSS Flexbox Cheat Sheet: Alignment, Wrapping, and Responsive Rows
A practical CSS Flexbox reference covering display:flex, flex-direction, gap, justify-content, align-items, flex-wrap, and flex shorthand.
Read postCSS Grid Cheat Sheet: Columns, Rows, Areas, and Responsive Layouts
A practical CSS Grid reference with repeat(), minmax(), auto-fit, alignment, named areas, and responsive layout examples.
Read postnpm Scripts Cheat Sheet: Commands, Arguments, and Automation
A developer reference for package.json scripts, npm run, pre/post hooks, environment variables, and safe task automation.
Read postFix TypeScript 'any' Spreading: Validate Unknown Values Safely
Troubleshoot TypeScript spread errors with unknown values, object narrowing, safe merge patterns, and typed generics.
Read postGit Commands Cheat Sheet
1. Quick Reference | Command | Description | | --- | --- | | git init | Initialize a new Git repository | | git clone [url] | Clone a Git repository from a URL | | git add [file] | Stage a file ...
Read post