← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

TypeScript Utility Types

TypeScript 2.1 Intermediate
debt(d5/e3/b3/t5)
d5 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'specialist tool catches it' (d5). The detection_hints list TypeScript compiler and ESLint as tools. Manual type duplication (e.g. writing PartialUser instead of Partial<User>) is not caught by basic compilation — TypeScript won't error on redundant manual types — but a specialist ESLint plugin (e.g. @typescript-eslint with custom rules) or dedicated type-coverage tooling can flag unnecessary duplication. It won't surface silently in production (ruling out d7/d9), but it's not caught by default linting either.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix describes replacing manual partial/pick type definitions with Partial<T>, Pick<T,K>, Omit<T,K>, or ReturnType<typeof fn>. This is a local refactor — swapping out duplicated type definitions for utility type calls — but may touch multiple interface/type declarations across a file or component, making it slightly more than a one-line patch (e1) but clearly not cross-cutting.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The burden of NOT using utility types is confined to the type definitions themselves. Manually duplicated types impose a maintenance tax whenever the base type changes (every field must be updated in all copies), but this stays largely within the type layer and doesn't spread architectural gravity across the whole codebase. Applies to web and CLI contexts, but the impact is scoped.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The canonical misconception is believing you must manually write partial versions of types, unaware that Partial<User> exists and auto-updates. Additionally, the common_mistakes note that Partial<T> is shallow — Partial does NOT recursively make nested objects partial — which is a documented gotcha many developers eventually learn. These two traps together justify t5: notable but documented surprises rather than catastrophic misbehavior.

About DEBT scoring →

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'

Added 15 Mar 2026
Edited 22 Mar 2026
Views 93
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 1 ping S 4 pings S 3 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 2 pings S 1 ping S 0 pings M 0 pings T 0 pings W
No pings yet today
No pings yesterday
ChatGPT 27 Amazonbot 11 Perplexity 11 Scrapy 8 Google 7 SEMrush 5 Ahrefs 4 Claude 2 Bing 2 PetalBot 2 Meta AI 1
crawler 78 crawler_json 2
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


✓ schema.org compliant