Utility Types (Partial, Pick, Omit, Record)
Utility types are built-in generic helpers like Partial , Pick , Omit , and Record that transform one type into a related type — making fields optional, selecting a subset of keys, or describing a dictionary — so you never have to copy-paste and edit an interface by hand.
Learn Utility Types (Partial, Pick, Omit, Record) in our free TypeScript course — an interactive lesson with runnable examples, a practice exercise and a…
Part of the free TypeScript course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
Think of a User interface as a master blueprint for a house. Utility types are the variant plans you stamp out from it without redrawing anything. Partial<User> is the "renovation checklist" where any room can be left blank. Pick<User, "id" | "name"> is the "front-door nameplate" showing only a couple of details. Omit<User, "password"> is the "public listing" with the private bits removed. Record<Room, Furniture> is a "room-by-room inventory". One blueprint, many derived plans — and they all stay in sync because they're computed from the original.
1. Partial, Required, Readonly, Pick & Omit
Start with one source type and derive the rest. Partial<T> makes every property optional — perfect for an "update" payload where the caller only sends the fields that changed. Required<T> does the reverse. Readonly<T> stops reassignment after construction. Pick<T, K> keeps only the keys you list, and Omit<T, K> keeps everything except them. Here is the full type-level picture:
The runnable example below shows the data these types describe: a full object, a patch merged over it (Partial), a picked subset (Pick), and an omitted-key version (Omit).
2. Record — Dictionaries & Lookup Tables
Record<K, V> describes an object whose keys are of type K and whose values are all of type V . With Record<string, number> you get an open dictionary (any string key, number value). With a union of literals as the key — Record<"red" | "green" | "blue", string> — the compiler insists every one of those exact keys is present, which is how you build a guaranteed-complete lookup table.
3. Filtering Unions & Reading Functions
The last group works on unions and functions. Exclude<T, U> removes the members of U from union T ; Extract<T, U> keeps only the members assignable to U . ReturnType<F> gives you whatever a function returns, and Parameters<F> gives you a tuple of its argument types — so you can derive types from a function instead of duplicating them.
🎯 Your Turn
Fill in the three blanks below. Each one mirrors a utility type at runtime: a Partial-style patch, a Pick-style subset, and an Omit via destructuring. Run it and match the expected output.
Build a small settings updater that exercises Partial (the merge), Pick (the public view), and Omit (dropping a key) all at runtime. Follow the outline, run it, and match the example output.
Practice quiz
Partial<T> makes every property of T:
- Required
- Readonly
- Optional
- A string
Answer: Optional. Partial<T> marks every property optional — ideal for an update or patch shape.
Required<T> is the inverse of:
- Partial
- Pick
- Record
- Omit
Answer: Partial. Required<T> forces every property to be present, undoing Partial.
Pick<User, 'id' | 'name'> produces a type with:
- Everything except id and name
- All keys optional
- A union of id and name
- Only id and name
Answer: Only id and name. Pick<T, K> keeps only the listed keys.
Omit<User, 'email'> produces a type that:
- Has only email
- Has everything except email
- Makes email optional
- Is never
Answer: Has everything except email. Omit<T, K> keeps everything except the named keys — the mirror of Pick.
Record<'red' | 'green' | 'blue', string> requires:
- Every one of those exact keys
- At least one of the keys
- No keys
- Numeric keys
Answer: Every one of those exact keys. With a literal-union key, Record demands every key be present — a complete lookup table.
Exclude<'guest' | 'user' | 'admin', 'guest'> is:
- 'guest'
- 'guest' | 'user' | 'admin'
- 'user' | 'admin'
- never
Answer: 'user' | 'admin'. Exclude<T, U> removes the members of U from the union T.
Extract<'guest' | 'user' | 'admin', 'admin' | 'owner'> is:
- 'guest' | 'user'
- 'admin'
- 'admin' | 'owner'
- never
Answer: 'admin'. Extract<T, U> keeps only the members of T assignable to U — here just 'admin'.
Parameters<typeof f> for f(name: string, age: number) is:
- string | number
- { name: string; age: number }
- never
Parameters<F> gives the argument types as a tuple, here [string, number].
Utility types like Partial and Pick at runtime:
- Add validation code
- Are erased — zero runtime cost
- Become classes
- Slow down objects
Answer: Are erased — zero runtime cost. They are compile-time only and produce no JavaScript output.
Record<K, V> is itself implemented as a:
- Conditional type
- Union type
Record<K, V> = { [P in K]: V } — a mapped type under the hood.