What is Record in TypeScript and how to use it correctly?
Hello everyone! I recently started learning TypeScript and came across the built-in `Record` type. I read the documentation, but I still don't fully understand its essence and when to use it.
I understand that there are interfaces and types, but `Record` looks somehow different. For example, I saw this code:
```typescript
const users: Record = {};
```
But I don't understand how this differs from a simple object `{ [key: string]: User }`. Or from `Map`? When to choose which?
My specific problem: I have a list of order statuses (pending, approved, rejected), and for each status I need to store some text (e.g., a color for display). I wrote this:
```typescript
const statusColors = {
pending: 'yellow',
approved: 'green',
rejected: 'red'
};
```
But TypeScript is complaining...
No answers yet.
Log in to leave an answer
Blogs