Why is the wrong type detected when using for (const var in Object.values){}?

11 Views Asked by At

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?
}

0

There are 0 best solutions below