Answer the question
In order to leave comments, you need to log in
How to use a for...in loop with TypeScript?
This code gives a compilation error (error text below), why is this happening, and how to fix it?
The code:
const fields = {
weather: "weather"
};
for (let key in fields) {
console.log("fields[key]: ", fields[key]);
}
The element is implicitly of type "any" because an expression of type "string" cannot be used to index type "{ weather: string; }".
No index signature found in type '{ weather: string; }' with type parameter 'string'.ts(7053)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question