Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split Iterator into Iterator and IterableIterator in es6.d.ts #2083

Merged
merged 5 commits into from
Feb 23, 2015

Conversation

JsonFreeman
Copy link
Contributor

All the ES6 iterators are themselves iterable, namely they have a Symbol.iterator that returns an iterator. However, a user could define their own iterator and associated iterable, where the iterator does not have this method. To convey this, we need to use IterableIterator in es6.d.ts, but still leave Iterator so that user defined iterators can work.

@@ -230,22 +230,22 @@ interface ArrayLike<T> {

interface Array<T> {
/** Iterator */
[Symbol.iterator] (): Iterator<T>;
[Symbol.iterator](): IterableIterator<T>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. It returns something htat is both an iterator, and something you can get an iterator off of?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, all the built-in ES6 iterators are like that.

}

interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}

interface IterableIterator<T> extends Iterable<T>, Iterator<T> { }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to fix this because it's not deeply iterable, so it won't work if you do:

var iter: IterableIterator<any>;
iter[Symbol.iterator]()[Symbol.iterator]();

The type IterableIterator needs to be recursive for this to work.

JsonFreeman added a commit that referenced this pull request Feb 23, 2015
Split Iterator into Iterator and IterableIterator in es6.d.ts
@JsonFreeman JsonFreeman merged commit 50f9ce4 into master Feb 23, 2015
@JsonFreeman JsonFreeman deleted the iterators branch February 23, 2015 23:24
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants