In the following code, I would expect val
to be detected as MyType
in typescript. However, it is being detected as string
which is the type of the key. Why?
type MyType = { one: string, two: string};
let sums: { [key: string]: MyType; } = {};
Object.values(sums).forEach(val => {
console.log(value.one) // val is of type MyType
});
for (const val in Object.values(sums)) {
console.log(val). // why is val a string and not MyType?
}