object-transforms
Record<K, V>
Creates an object type whose keys come from the union K and whose values all have type V. Useful for lookup tables, dictionaries, and enum-keyed maps.
type Record<K extends keyof any, V> = { [P in K]: V } Usage patterns
| Pattern | Purpose |
|---|---|
| Record<string, T> | Loose dictionary / index signature |
| Record<'a' | 'b', T> | Exhaustive map — every listed key required |
| Record<Enum, T> | Force a value for every enum member |
| Partial<Record<K, V>> | Sparse dictionary — keys optional |
Examples
type Roles = 'admin' | 'user' | 'guest';
type Permissions = Record<Roles, string[]>; TS will error if any of the three role keys is missing
const cache: Record<string, User> = {};
cache['42'] = user; Basic string-keyed dictionary — every access returns User (or undefined with noUncheckedIndexedAccess)
type PageMap = Record<number, string>; Numeric-keyed lookup — TS also allows number keys as strings at runtime
type SparseMap = Partial<Record<'a' | 'b' | 'c', number>>; Now each key is optional: { a?; b?; c? }
Gotcha
With `Record
Related utility types
Pick<T, K>
Builds a new type containing only the properties from T whose keys are in the union K. Ideal for narrowing large interfaces to the subset a function or component actually needs.
Partial<T>
Constructs a type where every property of T is set to optional. Useful for representing update payloads, patch objects, and configuration overrides where all fields may be omitted.
Readonly<T>
Marks every property of T as readonly, preventing reassignment after construction. Only enforced at compile-time — the underlying object is still mutable at runtime.
Omit<T, K>
Constructs a type by removing the properties in K from T. Unlike Pick, its K is not constrained to keyof T, so extra keys are silently ignored.
Required<T>
Removes optionality from every property of T, producing a type where all fields must be present. The -? mapping modifier strips the ? flag from every key.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never