TypeScript
/Intermediate
Record<Keys, Type>
Definition
A utility type that constructs an object type whose property keys are `Keys` and whose property values are `Type`. It maps a set of keys to a specific type.
Explain Like I'm New
It is a fast, incredibly readable way to type a Dictionary or Hash Map. Instead of writing out a complex Index Signature, you just say `Record<string, number>`, meaning 'This is an object where every key is a string, and every value is a number'.
Real World Example
Typing a theme configuration object: `const theme: Record<'dark' | 'light', ThemeColors>`. This forces the object to strictly contain exactly those two keys.
Common Use Cases
- •Dictionaries
- •Mapping strict enums/unions to specific values
Interactive Example
Loading Code Playground...
Interview Questions
basic
- What is the difference between `Record<string, number>` and `[key: string]: number`?
intermediate
- Can the `Keys` parameter be a union type?