Chapter 16: TypeScript Utility Types

1. First — What are Utility Types really? (the honest explanation)

Utility types are built-in generic type helpers that TypeScript gives you for free. They let you transform, filter, combine, unwrap, or modify existing types without rewriting them manually.

Think of them as type-level functions:

TypeScript

They live in the global scope → no import needed (as long as you’re using TypeScript ≥ 2.1 for the oldest ones).

Official list (as of early 2026 — from typescriptlang.org/docs/handbook/utility-types.html):

  • Awaited<T>
  • Partial<T>
  • Required<T>
  • Readonly<T>
  • Record<K, T>
  • Pick<T, K>
  • Omit<T, K>
  • Exclude<T, U>
  • Extract<T, U>
  • NonNullable<T>
  • Parameters<T>
  • ConstructorParameters<T>
  • ReturnType<T>
  • InstanceType<T>
  • ThisParameterType<T>
  • OmitThisParameter<T>
  • Uppercase<T>, Lowercase<T>, Capitalize<T>, Uncapitalize<T>

These are the official built-ins. Many teams also create custom ones (we’ll see a few popular patterns at the end).

2. The Most Frequently Used Ones (90% of daily work)

Let’s go through them in order of how often you’ll actually type them.

A. Partial<T> — make everything optional (very very common)

TypeScript

Real use-case: → PATCH / PUT requests (REST / tRPC / React Query mutations) → Form default values when editing (only send changed fields)

B. Required<T> — opposite: make everything required

TypeScript

Use-case: validation shapes (Zod .required(), form libraries)

C. Readonly<T> — freeze the object (immutability)

TypeScript

Real pattern: app/theme/config objects, Redux state slices (before Immer), props in React

D. Pick<T, K> — select only some keys

TypeScript

Super common in:

  • List views / table rows
  • Select / autocomplete responses
  • DTOs that expose subset of entity

E. Omit<T, K> — remove some keys (opposite of Pick)

TypeScript

Very frequent when:

  • Sending user to frontend
  • Logging / auditing
  • Creating public-facing types

F. Record<K, T> — object with specific keys & same value type

TypeScript

Also: string → component map, error codes → messages, feature flags

G. ReturnType<T> — extract what a function returns

TypeScript

Extremely useful with:

  • API functions
  • Selectors (Redux, Zustand)
  • Custom hooks that return complex objects

H. Parameters<T> — extract tuple of function parameters

TypeScript

Use-case: wrappers, middleware, testing argument spies

I. Awaited<T> (since 4.5 — very useful now)

TypeScript

Also handles nested promises: Awaited<Promise<Promise<number>>> → number

3. String utility types (template literal helpers — since 4.1)

TypeScript

Real usage:

  • React event handler names
  • CSS class prefixes
  • GraphQL field → input names

4. Set-like operations (very powerful for unions)

TypeScript

Use-case:

  • Filtering allowed roles / statuses
  • Union cleanup after conditional types

5. Quick reference table (print / bookmark this)

Utility What it does Most common real use-case (2026) Approx. frequency
Partial<T> All props optional PATCH requests, form partial updates ★★★★★
Required<T> All props required Creation DTOs, strict validation ★★★★
Readonly<T> All props readonly Configs, props, frozen state ★★★★
Pick<T, K> Keep only listed keys Previews, public shapes, table rows ★★★★★
Omit<T, K> Remove listed keys Remove secrets, internal fields ★★★★★
Record<K, T> { [key in K]: T } Maps, env, feature flags, permissions ★★★★
ReturnType<T> Type function returns API responses, hook returns, selectors ★★★★
Awaited<T> Unwrap Promise(s) async function results ★★★★
Parameters<T> Tuple of arguments Wrappers, test spies ★★★
Exclude / Extract Union subtract / intersect Allowed values filtering ★★★
NonNullable<T> Remove null/undefined After ?? / ! checks ★★★
Capitalize etc. String case transformation Event names, class names ★★

6. Popular custom utility patterns people add (beyond built-ins)

TypeScript

Your next steps (mini homework)

  1. Open TS playground
  2. Take any interface you have (or copy User from above)
  3. Try to create:
    • UpdateInput = Partial<…>
    • PublicUser = Omit<…, “password”>
    • UserCreate = Required<Pick<…, “name”|”email”>>
    • Config = Readonly<…>
    • Response = Awaited<ReturnType<your async fn>>

Which of these feel most useful for your current project right now?

Want to go deeper on:

  • DeepPartial / DeepReadonly patterns
  • Combining many utilities together (real tRPC / Zod-like shapes)
  • Writing your own mapped + conditional utilities
  • Utility types in React (props, state, hooks)

Just say — we’ll zoom in there next! 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *