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.
What You'll Learn
💡 Real-World Analogy
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.
📊 The Utility Types at a Glance
Utility
Does
Example
Partial<T>
All fields optional
Partial<User>
Required<T>
All fields required
Required<Config>
Readonly<T>
All fields read-only
Readonly<User>
Pick<T, K>
Keep only keys K
Pick<User, "id">
Omit<T, K>
Drop keys K
Omit<User, "pw">
Record<K, V>
Dictionary K→V
Record<string, number>
Exclude<T, U>
Remove U from union
Exclude<Role, "guest">
Extract<T, U>
Keep U from union
Extract<Role, "admin">
ReturnType<F>
Type a fn returns
ReturnType<typeof f>
Parameters<F>
Tuple of fn args
Parameters<typeof f>
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.
Common Errors (and the fix)
- ❌ Passing a non-key to Pick/Omit: Pick<User, "naem"> → "Type '"naem"' does not satisfy the constraint 'keyof User'". ✅ The second argument must be real keys of the type — fix the typo to "name" .
- ❌ Thinking Partial validates at runtime: Partial<User> does not stop a wrong-typed value from reaching you over the network — it only types the variable. ✅ Validate untrusted input (e.g. with a schema library) then treat it as the typed shape.
- ❌ Forgetting a required Record key: with Record<Color, string> , leaving out blue gives "Property 'blue' is missing". ✅ Either supply every key or use Partial<Record<Color, string>> if some may be absent.
- ❌ Mutating a Readonly: const u: Readonly<User>; u.name = "x" → "Cannot assign to 'name' because it is a read-only property". ✅ Build a new object with the spread syntax instead: { ...u, name: "x" } .
- ❌ Using Exclude on objects: Exclude / Extract filter unions , not object properties. ✅ To drop a property use Omit ; to drop a union member use Exclude .
Pro Tips
- 💡 Derive, don't duplicate: build "update", "create", and "summary" types from one source interface with Partial/Omit/Pick so they can never drift apart.
- 💡 Nest utilities freely: Partial<Pick<User, "name" | "email">> is a perfectly normal type.
- 💡 Prefer Omit for "create" payloads (everything minus the server fields) and Pick for narrow read views.
- 💡 Record with a literal union guarantees an exhaustive lookup table — the compiler flags any missing key.
Frequently Asked Questions
Mini-Challenge: Settings Updater
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.
🎉 Lesson Complete
- ✅ Partial<T> / Required<T> flip every field optional/required; Readonly<T> freezes them
- ✅ Pick<T, K> keeps only listed keys; Omit<T, K> drops them — ideal for views and create payloads
- ✅ Record<K, V> types dictionaries; a literal-union key demands an exhaustive table
- ✅ Exclude<T, U> / Extract<T, U> filter union members
- ✅ ReturnType<F> / Parameters<F> derive types straight from a function
- ✅ Utility types are compile-time only — zero runtime cost, pure descriptions of your data
- ✅ Next lesson: Mapped Types — the machinery that builds every one of these
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.
Continue this course
- Previous: Checkpoint: The Type System
- Next: Mapped Types