I've got following code snippet:
var iterator: IterableIterator<string> = iterBreadth(tree);
for(var item of iterator){
log(item)
}
iterBreadth is just a generator function that returns an iterator. Iterators in TypeScript are of type IterableIterator<T> where T is a string in my case.
My question is - why is the playground yelling at me at the for..of iterator loop line:
?
How come iterators are limited to arrays and string only?
I've found at the official docs that, when targeting ES3 or ES5, only arrays are allowed in for..of loops. But that doesn't explain what are strings doing in the playground erorr message.
Besides, I can see that typescript is having hard time transpiling for..of. The following code seems to be transpiled against arrays precisely, since it's just iterating over indices (0, 1, 2), not calling next:
var iterator = iterBreadth(tree);
for (var _i = 0, iterator_1 = iterator; _i < iterator_1.length; _i++) {
var item = iterator_1[_i];
log(item);
}

es6(or above) to be able to do that. But it seems that you know that already, so what exactly are you asking? Why targettinges6is needed?stringtype?! I find it misleading.