Record<Key, Value>

Produces an object type where keys are of type Key and values are of Value.

This utility is often used to define a mapping from values of a particular type to values of another type. In many cases, it is an alternate way to write an object index signature.

When writing an index signature, the key type must be string. Record allows us to use more specific types as keys, like a particular set of known strings.

When defining a specific key type, each key must be present - TypeScript will catch missing or extra keys.

Some more examples.

You can construct your own Record type with object index signatures.

Was this page helpful?