utility types
Generic types built into TypeScript, such as Partial, Pick and ReturnType, that compute a new type from an existing one.
In more detail
They let you derive create, update and response shapes from one entity type instead of writing near-copies that drift apart. Most are defined with mapped and conditional types that you can also write yourself.
Related terms
- Partial<T> — The utility type that makes every property of T optional, used for update or patch payloads.
- Pick<T, K> — The utility type that keeps only the listed keys K of type T, like an allowlist of fields.
- Omit<T, K> — The utility type that copies type T without the listed keys K, like a denylist of fields.
- mapped type — A type that builds a new object type by looping over a set of keys, such as { [K in keyof T]: T[K] }.
- conditional type — A type that picks one of two types depending on whether a type is assignable to another, written like a ternary expression with extends.
- DTO — A plain object whose only job is to carry data across a boundary, such as the body of an API request or response.
Taught in
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript