Currently, GeneratorFunctions return a Generator, which simply extends Iterator:
interface Generator extends Iterator<any> { }
This is unfortunate because next and throw are optional in Iterators:
interface Iterator<T> {
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}
GeneratorsFunctions could theoretically throw an error at any time! In addition, they do always return something, even if it's undefined. Therefore, simply extending Iterator isn't specific enough.
So why not make throw and return required properties of Generator?
The current situation causes some rather frustrating problems. For example, this ticket.
True, the ECMA2015 schema says:
A Generator object is an instance of a generator function and conforms to both the Iterator and Iterable interfaces.
However, I'd argue that a more specific implementation of Iterator still conforms to Iterator :)
Currently, GeneratorFunctions return a Generator, which simply extends Iterator:
This is unfortunate because
nextandthroware optional in Iterators:GeneratorsFunctions could theoretically throw an error at any time! In addition, they do always return something, even if it's undefined. Therefore, simply extending Iterator isn't specific enough.
So why not make
throwandreturnrequired properties of Generator?The current situation causes some rather frustrating problems. For example, this ticket.
True, the ECMA2015 schema says:
However, I'd argue that a more specific implementation of Iterator still conforms to Iterator :)