Utility types: Partial, Pick
📚 What are Utility Types in TypeScript? TypeScript comes with built-in helper types called utility types that transform existing types. Instead of rewriting types from scratch for every variation, you can use Partial<T> (makes all optional), Pick<T, K> (keeps only specific keys), Omit<T, K> (remov…

Appy Says…
TypeScript ships with a set of built-in type transformers — Partial, Required, Pick, Omit, Readonly. These let you create new types from existing ones without redefining everything from scratch. They're one of TypeScript's most useful features.
What are TypeScript Utility Types?
TypeScript's utility types transform existing types into new variants. They're generic types built into TypeScript's standard library.
- •
Partial<T>— makes all properties optional - •
Required<T>— makes all properties required (removes ?) - •
Readonly<T>— makes all properties readonly - •
Pick<T, K>— keep only listed properties - •
Omit<T, K>— remove listed properties - •
Record<K, V>— object with keys K and values V - •
NonNullable<T>— removes null and undefined from T
Think of it like Minecraft recipe modifiers
Take a diamond sword recipe and make a variant: enchanted version (add properties), stripped version (remove enchantments), read-only display version (no edits). Utility types do the same: take a base type and create targeted variants — no rewriting needed.
How It Works
- •1.
type UserUpdate = Partial<User>;— all User fields optional (for PATCH requests) - •2.
type UserPreview = Pick<User, 'id' | 'name' | 'avatar'>; - •3.
type UserWithoutPassword = Omit<User, 'password'>; - •4.
type ReadonlyConfig = Readonly<Config>; - •5. Combine:
type SafeUser = Readonly<Omit<User, 'password'>>; - •6.
ReturnType<typeof fn>— infer a function's return type
Real-World Examples
- •PATCH API body:
Partial<User>— only fields being updated - •Safe API response:
Omit<User, 'passwordHash'>— never send sensitive fields - •State update:
Pick<AppState, 'theme' | 'language'> - •Config defaults:
Required<Config>— after applying defaults, all fields present
Key Facts
- •All utility types are defined in TypeScript's lib.d.ts using mapped types and conditional types
- •
ReturnType<T>andParameters<T>extract function signature types - •
Awaited<T>unwraps a Promise type:Awaited<Promise<User>>→User - •You can build custom utility types:
type Nullable<T> = T | null;
Watch Out!
Partial makes ALL properties optional — even ones that are conceptually required. For a PATCH endpoint you might want Pick<User, 'name' | 'bio'> as Partial, not the whole User type. Be precise about which fields are actually editable.
Remember
Partial (all optional), Required (all required), Pick (keep keys), Omit (remove keys), Readonly (immutable), Record (key-value map). Combine them to create precise types from existing ones without rewriting.
What You Learned
- •Utility types transform existing types: Partial, Required, Pick, Omit, Readonly, Record
- •Combine them:
Readonly<Omit<User, 'password'>> - •Unlocks: PATCH API types, safe API responses, immutable configs, any targeted type variant
Key Facts
- →All utility types are defined in TypeScript's lib.d.ts using mapped types and conditional types
- →
ReturnType<T>andParameters<T>extract function signature types - →
Awaited<T>unwraps a Promise type:Awaited<Promise<User>>→User - →You can build custom utility types:
type Nullable<T> = T | null;
Real-World Examples
Remember
Partial (all optional), Required (all required), Pick (keep keys), Omit (remove keys), Readonly (immutable), Record (key-value map). Combine them to create precise types from existing ones without rewriting.
Quick Quiz
Partial<T> does?