TS2488
error TS2488: Type ‘
{ [month: number]: string; }
‘ must have a ‘[Symbol.iterator]()
‘ method that returns an iterator.
Solution
You have to add a property called [Symbol.iterator]
to your object. The value of this property has to return an iterator. Here you can learn how to create an iterator.
Alternative Solution
If you run into this problem because of a for-of loop, then you can mitigate the problem by using the forEach()
method of arrays:
Broken Code ❌
1 |
|
Fixed Code ✔️
1 |
|