The following code works in my browser without the typings, but TypeScript emits an error saying that gen() doesn't have a [Symbol.iterator] method which is what is expected for an Iterable. This limitation seems strange to me as AFAIK an .Iterator is a valid object to pass to for...of
function *gen(): Iterator<number> {
yield 1
yield 2
yield 3
}
for (const val of gen()) {
console.log(val)
}
Could you explain me what I'm doing wrong here?
Edit: Removing the return type from the previous code thus letting TypeScript guess what it is gave me IterableIterator, which is making TypeScript happy. So am I not allowed to use a mere Iterator in a for...of?