What is Record<K, V> in TypeScript and how to use it?
Hello! I started learning TypeScript and came across the `Record` type. Honestly, I don't fully understand what it's for and how it differs from a regular object or interface.
Let's say I have this code:
```typescript
interface User {
id: number;
name: string;
}
const users: { [key: number]: User } = {
1: { id: 1, name: 'Anna' },
2: { id: 2, name: 'Boris' }
};
```
I see that I can write `{ [key: number]: User }`. But in the documentation I encountered `Record`. Is this the same thing? Or are there nuances?
Also, I tried to create an object where the keys are strings that can only be specific values, for example, order statuses: 'pending', 'shipped', 'delivered'. I want the keys to be strictly from this set, and the values to be a date (string). Ka
No answers yet.
Log in to leave an answer
Blogs
Monitoring Kotlin Applications: Advanced Metrics and Alerts
How to Pass a Go Interview: Top Advanced-Level Questions
Parsing in TypeScript: How to Scrape Data Faster and More Reliably
C++ in 2025: A Complete Learning Plan from Beginner to Pro