How do you iterate over a set in TypeScript? for..of does not work:
\'Set\' is not an array type or a string type
.for
You can still use .forEach
with the correct this
by using a regular function instead of an arrow function
mySet.forEach(function(item){
expect(this).toEqual(item);
});
Compared to
class MyClass{
...
doSomething():{
mySet.forEach((item) => {
expect(this instanceof MyClass).toEqual(true);
});
}
}
Another way to iterate is to use a for loop over the values
for(item of mySet.values()){
...
}
More information on iterating Set
with foreach can be found here