Reference / TypeScript
Record<Keys, Type>
Constructs an object type whose property keys are Keys and whose property values are Type. Useful for mapping properties of one type to another.
Syntax
type Record<K extends keyof any, T> = { [P in K]: T; }Parameters
| Name | Type | Description |
|---|---|---|
| Keys | string | number | symbol | The allowable property key identifiers. |
| Type | any | The value type assigned to each key. |
Examples
Mapping roles to permissions
type Role = 'admin' | 'editor' | 'viewer';
const permissions: Record<Role, string[]> = {
admin: ['read', 'write', 'delete'],
editor: ['read', 'write'],
viewer: ['read'],
};Guarantees that all keys in the union are defined in the record.