I am working with an object that has an interface and I am interested in accessing values dynamically using property keys.
const userData: IUser = {
username: "test",
namespace: "test",
password: "test"
}
Object.keys(userData).forEach(property=>{
// Issue: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'IUser'.
console.log(userData[property]);
})
// This works
console.log(userData["username"]);
// This also works
const key = "username";
console.log(userData[key]);
Additionaly,
userData.hasOwnProperty(property)
does not solve the issue.