We can use the utility type Record
to construct an object type using certain key/value pairs in order to link to the properties of an object which contains different data types.
Example
interface Person {
age: number;
gender: string;
}
type PersonName = "adam" | "bilal" | "aisha";
const people: Record<PersonName, Person> = {
adam: {age: 20, gender: "Male"},
bilal: {age: 25, gender: "Male"},
aisha: {age: 23, gender: "Female"}
}
console.log(people.aisha) // {age: 23, gender: "Female"}