xxxxxxxxxx
const obj = {
name: 'Bobby Hadz',
country: 'Chile',
};
​
type ObjectKey = keyof typeof obj;
​
const myVar = 'name' as ObjectKey;
​
console.log(obj[myVar]); // 👉️ Bobby Hadz
​
https://bobbyhadz.com/blog/typescript-access-object-property-dynamically