Avatar ·

How to specify a type for all elements of an object (index members) in TypeScript?

Hi! I recently started learning TypeScript and ran into a problem. I have an object that stores user data. The keys are string IDs, and the values are objects with information. I need TypeScript to check that all values in this object match a specific type, regardless of which keys I use. Here's an example of what I'm trying to do: ```typescript interface User { name: string; age: number; } // This is how I want to declare an object where all values are User let users: { [key: string]: User } = {}; users["user1"] = { name: "Alice", age: 30 }; // Ok users["user2"] = { name: "Bob", age: "25" }; // Error, age is a string, not a number ``` This code works, but I'm not sure if this is the correct approach. I've heard about Record, but I don't understand how