TypeScript Utility Types
Also Known As
Partial
Omit
Pick
Record
ReturnType
utility types
TL;DR
Built-in generic types that transform existing types — Partial, Required, Pick, Omit, Record, Readonly, ReturnType — eliminating the need to manually duplicate type definitions.
Explanation
TypeScript ships with utility types for common transformations: Partial<T> makes all properties optional; Required<T> makes all required; Readonly<T> makes all readonly; Pick<T,K> selects a subset of properties; Omit<T,K> removes properties; Record<K,V> creates an object type with specific key/value types; ReturnType<F> extracts a function's return type; Parameters<F> extracts parameter types. These eliminate the copy-paste type maintenance problem — derive types from a single source of truth.
Diagram
flowchart LR
BASE[User type<br/>id name email role]
BASE -->|Partial| PART[All fields optional<br/>good for update DTOs]
BASE -->|Required| REQ[All fields required]
BASE -->|Readonly| RO[All fields readonly]
BASE -->|Pick name email| PICK[Only name and email]
BASE -->|Omit role| OMIT[All except role]
BASE -->|Record string User| REC[Dictionary of Users]
subgraph Common_Uses
PART -->|patch endpoints| USE1[UpdateUserDto]
PICK -->|public API| USE2[PublicProfile]
RO -->|immutable config| USE3[AppConfig]
end
style BASE fill:#6e40c9,color:#fff
style PART fill:#1f6feb,color:#fff
style PICK fill:#238636,color:#fff
style RO fill:#d29922,color:#fff
Common Misconception
✗ You need to manually write partial versions of types — Partial<User> is always available; writing type PartialUser = { name?: string; email?: string } is duplication.
Why It Matters
Utility types keep type definitions DRY — when User adds a field, Partial<User>, Pick<User,'name'|'email'>, and Omit<User,'password'> all update automatically.
Common Mistakes
- Manually writing partial or pick types instead of using Partial<T> and Pick<T,K>.
- Using Record<string, any> when a more specific value type is known.
- Not using ReturnType<typeof fn> to infer return types — avoids duplication when the function signature changes.
- Forgetting that utility types are shallow — Partial<T> does not make nested objects partial; use DeepPartial for that.
Code Examples
✗ Vulnerable
// Manually duplicated partial type — drifts when User changes:
type User = { id: number; name: string; email: string; role: string };
// Manual copy — must be updated every time User changes:
type UpdateUserDTO = {
name?: string;
email?: string;
role?: string;
};
✓ Fixed
// Utility types — derived, never drift:
type User = { id: number; name: string; email: string; role: string; password: string };
type UpdateUserDTO = Omit<Partial<User>, 'id' | 'password'>;
// Equivalent to: { name?: string; email?: string; role?: string }
// Automatically includes new User fields, excludes id and password
type UserPublic = Omit<User, 'password'>; // Safe for API responses
type UserKeys = keyof User; // 'id' | 'name' | 'email' | 'role' | 'password'
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
15 Mar 2026
Edited
22 Mar 2026
Views
64
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
ChatGPT 27
Perplexity 11
Amazonbot 9
Google 6
Ahrefs 2
SEMrush 2
Also referenced
How they use it
crawler 57
Related categories
⚡
DEV INTEL
Tools & Severity
🟢 Low
⚙ Fix effort: Low
⚡ Quick Fix
Use Partial<T> for optional update DTOs, Pick<T,K> for projections, Omit<T,K> to exclude sensitive fields, and ReturnType<typeof fn> to derive types from function return values
📦 Applies To
typescript 2.1
web
cli
🔗 Prerequisites
🔍 Detection Hints
Manually duplicating interface with all optional fields when Partial<T> exists; no use of utility types causing type duplication
Auto-detectable:
✓ Yes
typescript
eslint
⚠ Related Problems
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Medium
Context: File