Reference8 min read · Updated 2025-06-01

TypeScript Utility Types: The Complete Cheatsheet

A complete reference for all TypeScript built-in utility types — Partial, Required, Readonly, Pick, Omit, Record, Exclude, Extract, NonNullable, and more — with real examples.

💡 Practice these concepts interactively with AI feedback

Start Practicing →

TypeScript Utility Types: The Complete Cheatsheet

TypeScript ships with powerful generic utilities that transform types. Knowing them saves hundreds of lines of manual type definitions.

Object Modification Utilities

### Partial — Make All Properties Optional

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

type UserUpdate = Partial<User> // { id?: number; name?: string; email?: string }

function updateUser(id: number, changes: Partial<User>) { // changes can contain any subset of User fields } updateUser(1, { name: 'Alice' }) // valid — only name updateUser(1, { email: 'a@b.com', name: 'Alice' }) // also valid

### Required — Make All Properties Required

interface Config {   debug?: boolean   timeout?: number   retries?: number }

type FinalConfig = Required<Config> // { debug: boolean; timeout: number; retries: number }

### Readonly — Prevent Mutation

type ReadonlyUser = Readonly<User> // { readonly id: number; readonly name: string; readonly email: string }

const user: ReadonlyUser = { id: 1, name: 'Alice', email: 'a@b.com' } user.name = 'Bob' // ❌ Error: Cannot assign to 'name' because it is read-only

### Record — Map Keys to Values

type StatusMap = Record<'active' | 'inactive' | 'banned', { count: number }> // { active: { count: number }; inactive: { count: number }; banned: { count: number } }

const statusCounts: Record<string, number> = {} statusCounts['active'] = 42 // safe

Key Selection Utilities

### Pick — Select Specific Properties

interface User { id: number; name: string; email: string; password: string }

type PublicUser = Pick<User, 'id' | 'name' | 'email'> // { id: number; name: string; email: string } // password is excluded — safe to send to client

### Omit — Exclude Specific Properties

type UserWithoutPassword = Omit<User, 'password'> // { id: number; name: string; email: string }

// Common pattern: omit id when creating new entities type CreateUserInput = Omit<User, 'id'>

### Pick vs Omit — When to Use Which

  • Use Pick when you know the small set of properties you WANT
  • Use Omit when you know the small set of properties you DON'T WANT
  • If the type has 20 fields and you want 18, Omit is cleaner than Pick

Union Type Utilities

### Exclude — Remove Types from Union

type Status = 'active' | 'inactive' | 'banned' | 'pending' type LiveStatus = Exclude<Status, 'banned' | 'pending'> // 'active' | 'inactive'

type NonNullableId = Exclude<string | null | undefined, null | undefined> // string

### Extract — Keep Only Matching Types

type StringOrNum = string | number | boolean type OnlyStrings = Extract<StringOrNum, string> // string

// Useful for narrowing unions: type StringEvents = Extract<DOMEvent, MouseEvent | KeyboardEvent>

### NonNullable — Remove null and undefined

type MaybeUser = User | null | undefined type DefiniteUser = NonNullable<MaybeUser> // User

function processUser(user: NonNullable<typeof maybeUser>) { // TypeScript knows user is defined here }

Function Type Utilities

### ReturnType — Extract Function Return Type

function createUser(name: string, email: string) {   return { id: Math.random(), name, email, createdAt: new Date() } }

type User = ReturnType<typeof createUser> // { id: number; name: string; email: string; createdAt: Date } // No need to manually define User!

### Parameters — Extract Function Parameter Types

function fetchData(url: string, options: RequestInit, timeout: number) { / / }

type FetchParams = Parameters<typeof fetchData> // [url: string, options: RequestInit, timeout: number]

// Forward exact same parameters to a wrapper function cachedFetch(...args: Parameters<typeof fetchData>) { return fetchData(...args) }

### Awaited — Unwrap Promise Type

async function getUser(): Promise<User> { / / }

type UserResult = Awaited<ReturnType<typeof getUser>> // User (Promise is unwrapped)

Combining Utilities

The real power comes from composing utilities:

// Patch endpoint: all fields optional except id (which is required)
type UserPatch = Required<Pick<User, 'id'>> & Partial<Omit<User, 'id'>>

// Read-only computed state type AppState = Readonly<{ user: NonNullable<User> settings: Required<Settings> cache: Record<string, unknown> }>

Practice TypeScript utility type questions at [JSPrep Pro](/auth).

Put This Into Practice

Reading articles is passive. JSPrep Pro makes you actively recall, predict output, and get AI feedback.

Start Free →Browse All Questions

Related Articles

Deep Dive
We Built a RAG-Powered AI Question Engine Into a JavaScript Interview Platform — Here's Exactly How It Works
12 min read
Build Systems
Monorepo with Turborepo vs Nx: The Complete Comparison (2025)
9 min read
Core Concepts
map() vs forEach() in JavaScript: Which One to Use and Why It Matters
7 min read