I have this really easy problem, where I want to loop through an Object in TypeScript.
const an_object = {
one: 1,
two: 2,
three: 3
};
for (let key in an_object) {
let value = an_object[key];
// Do something with value
}
This row let value = an_object[key];
is causing a TypeScript error:
[react-scripts] Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ one: number; two: number; three: number; }'.
I'm new to TypeScript and don't really understand the problem.
This works fine on JavaScript but not on TypeScript.
Any suggestions on how to loop through an object in TypeScript correctly, without getting errors?