Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
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

NameTypeDescription
Keysstring | number | symbolThe allowable property key identifiers.
TypeanyThe 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.