Code Reference

Utility Types

_TypeScript · Reference cheat sheet_

Utility Types

TypeScript · Reference cheat sheet


📖 Overview

TypeScript ships built-in utility types for common transformations: making props optional/required, picking keys, extracting from unions, and more. They are implemented with mapped and conditional types under the hood (TS 5.x).

🧩 Core concepts

  • Object helpersPartial, Required, Readonly, Pick, Omit, Record.
  • Union helpersExclude, Extract, NonNullable.
  • Function helpersParameters, ReturnType, ConstructorParameters, InstanceType.
  • AsyncAwaited<T> unwraps nested Promises.
  • String helpersUppercase, Lowercase, Capitalize, Uncapitalize.
  • ThisType / NoInfer — advanced inference control (NoInfer in TS 5.4+).

💡 Examples

interface User {
  id: string;
  name: string;
  email?: string;
}

type UserPatch = Partial<User>;
type UserRequiredEmail = Required<Pick<User, "email">> & Omit<User, "email">;
type UserPreview = Pick<User, "id" | "name">;
type UserWithoutEmail = Omit<User, "email">;

type Role = "admin" | "user" | "guest";
type Staff = Exclude<Role, "guest">; // "admin" | "user"
type AdminOnly = Extract<Role, "admin">;

type Maybe = string | null | undefined;
type Sure = NonNullable<Maybe>; // string

function createUser(name: string, age: number) {
  return { name, age };
}
type Args = Parameters<typeof createUser>; // [string, number]
type Out = ReturnType<typeof createUser>;

type Payload = Awaited<Promise<Promise<number>>>; // number

type Event = `on${Capitalize<"click">}`; // "onClick"

⚠️ Pitfalls

  • Omit is not type-safe for renaming/refactoring keys the way a constrained Pick can be.
  • Partial makes every key optional, including nested objects (shallow only).
  • Record<string, T> allows any string key — prefer string literal unions when the set is closed.
  • Utility types operate at compile time only — they emit no runtime code.

On this page