TypeScript theorytheory 0/50 · 0%
Types · medium

25. Utility types: Partial, Pick, Omit

Built-in generics that transform existing types.

TypeScript ships a library of utility types that transform an existing type into a new one without repeating field definitions.

ts
interface Token { symbol: string; decimals: number; totalSupply: number; }

type TokenPatch = Partial<Token>;               // all fields optional
type TokenSummary = Pick<Token, "symbol" | "decimals">; // only these fields
type TokenWithoutSupply = Omit<Token, "totalSupply">;   // all except this one

function updateToken(id: string, patch: Partial<Token>) { /* ... */ }
updateToken("1", { decimals: 6 }); // OK: other fields optional

`Required<T>` is the opposite of `Partial` (forces all fields to be required), and `Readonly<T>` makes every field `readonly`. Composing these keeps a single source of truth (`Token`) instead of hand-maintaining several near-duplicate interfaces.

Check your understanding

  1. 1. What does `Partial<Token>` produce?

  2. 2. What does `Pick<Token, "symbol" | "decimals">` produce?

  3. 3. What is the opposite of `Partial<T>`?