const str = 'name' as string; const obj = { name: 'James Doe', country: 'Chile', }; // 👇️ "James Doe" console.log(obj[str as keyof typeof obj]); // 👇️ type T = "name" | "country" type T = keyof typeof obj;
const str = 'name' as string; const obj = { name: 'James Doe', country: 'Chile', }; // 👇️ "James Doe" console.log(obj[str as keyof typeof obj]); // 👇️ type T = "name" | "country" type T = keyof typeof obj;