TypeScript Utility Types Cheat Sheet: Practical Patterns for Real-World Code
utility-typestype-manipulationcheat-sheetadvanced-typescripttypescript-best-practices

TypeScript Utility Types Cheat Sheet: Practical Patterns for Real-World Code

TTypeScript Toolbox Editorial Team
2026-11-28
6 min read

A practical TypeScript utility types cheat sheet covering Partial, Pick, Omit, Record, ReturnType, Awaited, and custom patterns.

TypeScript utility types let you reshape existing models instead of duplicating them. This practical cheat sheet explains when to use Partial, Pick, Omit, Record, ReturnType, Awaited, and custom mapped types, with examples you can adapt for APIs, forms, configuration, and reusable libraries.

Overview

Utility types are built-in or user-defined type transformations. They operate at compile time, so they do not validate JavaScript values at runtime. Their main benefit is consistency: a request type, form model, or callback signature can be derived from a source type and updated automatically when that source changes.

The most useful decision is to start with the shape you already have:

  • Use Partial<T> when every property is optional.
  • Use Pick<T, K> when you need an explicit subset.
  • Use Omit<T, K> when you need everything except selected properties.
  • Use Record<K, V> for a keyed collection with a known value type.
  • Use ReturnType<F> to derive a function’s returned type.
  • Use Awaited<T> to model the resolved value of a promise-like type.
  • Use custom mapped or conditional types when a built-in transformation is not precise enough.

These tools are especially valuable in advanced TypeScript patterns, but they do not replace good domain boundaries. A type derived from an internal database model may expose fields that should never appear in a public API. Derive types deliberately, then review the resulting shape.

Template structure

Keep a source model as the canonical description of an entity, then derive specialized views from it. The following example represents a user in an application:

interface User {
  id: string;
  name: string;
  email: string;
  role: "admin" | "member";
  createdAt: Date;
  marketingOptIn: boolean;
}

Core TypeScript utility types cheat sheet

Utility typeTransformationExample resultTypical use
Partial<T>Makes all properties optional{ name?: string; email?: string }Patch data, drafts, form state
Required<T>Makes all properties requiredEvery optional property becomes requiredValidated or finalized configuration
Readonly<T>Prevents property reassignment through the typereadonly id: stringImmutable inputs and snapshots
Pick<T, K>Keeps only keys in K{ id: string; name: string }DTOs, table rows, public views
Omit<T, K>Removes keys in KUser without id and createdAtCreate or update payloads
Record<K, V>Maps keys to one value typeRecord<Role, string>Lookups, labels, feature maps
Exclude<T, U>Removes union members assignable to UExclude<Role, "admin">Narrowing allowed values
Extract<T, U>Keeps union members assignable to UOnly matching union membersSelecting compatible event or key types
NonNullable<T>Removes null and undefinedstring from string | nullPost-validation values
Parameters<F>Returns a function’s parameter tuple[id: string, limit?: number]Wrappers, mocks, adapters
ReturnType<F>Returns a function’s return typeThe inferred result of FSelectors, factories, service adapters
Awaited<T>Unwraps promise-like resultsUser from Promise<User>Async service and API types

For a broader collection of DTO, form, configuration, and API patterns, see the TypeScript Utility Types Cookbook.

How to customize

Choose explicit keys for public contracts

Pick makes the intended boundary visible:

type UserSummary = Pick<User, "id" | "name" | "role">;

type UserCreateInput = Omit<User, "id" | "createdAt">;

Use Pick when the consumer should receive a small, stable view. Use Omit when the source model is the right foundation and the excluded fields are clearly defined. For long-lived API contracts, an independently declared type can sometimes be safer than exposing every future change to an internal model.

Use Record for complete maps

A Record example is useful when every member of a union must have a value:

type Role = User["role"];

const roleLabels: Record<Role, string> = {
  admin: "Administrator",
  member: "Member"
};

This expresses a stronger guarantee than { [key: string]: string }. The latter accepts arbitrary keys, while Record<Role, string> keeps the map aligned with the declared role values.

async function loadUser(id: string): Promise<User> {
  // implementation omitted
  throw new Error("not implemented");
}

type LoadUserResult = Awaited<ReturnType<typeof loadUser>>;
// User

ReturnType prevents a separately written result type from drifting away from the implementation. Combining it with Awaited gives the resolved value for asynchronous functions. This pattern is useful for service wrappers, test fixtures, and state selectors, but avoid hiding a complicated function signature behind several layers of indirection.

Build a focused custom utility

Mapped types are appropriate when you want to transform every property according to a rule:

type Nullable<T> = {
  [K in keyof T]: T[K] | null;
};

type NullableUser = Nullable<Pick<User, "name" | "email">>;

Another common pattern is a type that makes only selected properties optional:

type PartialBy<T, K extends keyof T> =
  Omit<T, K> & Partial<Pick<T, K>>;

type UserWithOptionalEmail = PartialBy<User, "email">;

Document custom utilities briefly and give them domain-specific names when possible. A readable alias such as UserPatch is often easier to use in application code than repeatedly exposing a complex composition.

Examples

Before: duplicated request models

interface CreateUserRequest {
  name: string;
  email: string;
  role: "admin" | "member";
  marketingOptIn: boolean;
}

interface UpdateUserRequest {
  name?: string;
  email?: string;
  role?: "admin" | "member";
  marketingOptIn?: boolean;
}

After: derived models

type CreateUserRequest = Omit<User, "id" | "createdAt">;
type UpdateUserRequest = Partial<CreateUserRequest>;

The second version removes repetition and makes the relationship between create and update operations clear. It is still worth deciding whether fields such as role should be writable by every caller. If not, use a narrower composition:

type SelfServiceUpdate = Partial<Pick<User, "name" | "marketingOptIn">>;

Utility types also work well with discriminated unions:

type AppEvent =
  | { type: "created"; user: User }
  | { type: "deleted"; userId: string };

type EventType = AppEvent["type"];
type CreatedEvent = Extract<AppEvent, { type: "created" }>;

Here, indexed access obtains the event names, while Extract selects the union member whose discriminator matches. This is useful for typed event handlers without manually repeating the entire union.

Remember that utility types provide static guarantees only. Data received from HTTP requests, environment variables, or JSON files still needs runtime validation before it is treated as a trusted User. TypeScript runtime validation and static utility types solve related but different problems.

When to update

Revisit this cheat sheet when your project adopts a new TypeScript version, changes its API or domain models, or introduces a new pattern for forms, configuration, or service boundaries. Built-in utility types and their behavior are part of the language’s evolving type system, so verify examples against the compiler version used by your project rather than assuming every codebase has identical settings.

During a pull request, check whether a new type is duplicating an existing model, whether Partial makes too many fields optional, and whether an Omit unintentionally exposes future internal fields. Also check whether a custom utility improves clarity or merely compresses code. If a utility type produces confusing compiler errors, consult the common TypeScript errors diagnostic guide and the compiler errors reference.

  1. Identify the canonical source type.
  2. Write down the exact fields the consumer needs.
  3. Choose Pick, Omit, or Partial based on that boundary.
  4. Use Record for constrained key-to-value maps.
  5. Derive function results with ReturnType and Awaited where it improves consistency.
  6. Run the compiler and tests, then review the generated shape as part of the API contract.

Keep this reference near the codebase’s type conventions, update examples when those conventions change, and prefer the smallest transformation that accurately describes the data. That approach makes TypeScript utility types a maintainable design tool rather than a collection of clever aliases.

Related Topics

#utility-types#type-manipulation#cheat-sheet#advanced-typescript#typescript-best-practices
T

TypeScript Toolbox Editorial Team

TypeScript Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.