Record<K, T>

Constructs an object type whose keys are K and whose values are T.

Since TS 2.1 Spec ↗

Syntax

Record<Keys, Type>

Returns

object type — A type with one property of type T for each key in the union K.

Examples

type Role = 'admin' | 'user' | 'guest';

const access: Record<Role, boolean> = {
  admin: true,
  user: true,
  guest: false,
};
const scores: Record<string, number> = {};
scores['alice'] = 10;

Notes

When K is a literal union TypeScript requires every key to be present. With `string` or `number` as K it behaves like an index signature. Prefer `Record` over an inline index signature when the value type is descriptive.

See also