Skip to content
Back to all posts
Technology

TypeScript Utility Types Cheat Sheet: Pick, Omit, Partial and More

Practical examples of TypeScript Partial, Required, Pick, Omit, Record, ReturnType, Awaited, Extract, and Exclude.

3 min read

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:

typescript
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 |

typescript
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

typescript
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

typescript
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

typescript
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

typescript
type MaybeName = string | null | undefined;
type Name = NonNullable<MaybeName>; // string

NonNullable 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