-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
built-in iterators should be disposable #59633
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the code change, but I had a couple of questions about the tests.
using it3 = new MyIterator(); | ||
using it4 = [].values(); | ||
using it5 = new Map<string, string>().entries(); | ||
using it6 = new Set<string>().keys(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why these succeed when using it7 = i
fails. They're all Iterators too. Where do they get a [Symbol.dispose]
method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it7
is illustrating that the Iterator
interface (which only describes a minimal Iterator compatible with for..of
) does not implement Symbol.dispose
. Only iterators that inherit from the IteratorObject
interface (which represents the global Iterator.prototype
value) will have a Symbol.dispose
by default.
Iterators returned from values()
/keys()
/entries()
on Map
/Set
/Array
/etc. will inherit from IteratorObject
and thus are disposable.
@@ -1874,4 +1874,140 @@ describe("unittests:: evaluation:: awaitUsingDeclarations", () => { | |||
"catch", | |||
]); | |||
}); | |||
|
|||
it("deterministic collapse of Await", async () => { | |||
const { main, output } = evaluator.evaluateTypeScript( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these tests of existing functionality? I don't see how changing the type of [Async]IteratorObject would change its runtime behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was in the wrong test suite. I merely moved while adding other tests.
I'm seeing some build errors that are related to this: Rather than, interface IteratorObject<T, TReturn, TNext> extends Disposable {
} Should it have been: interface Iterator<T, TReturn, TNext> extends Disposable {
}
|
No, it being on the interface isn't correct, I think you just need to update your |
Thx for the guidance! For anyone else looking into this, the referenced PR is: DefinitelyTyped/DefinitelyTyped@8c36e53 |
This updates the definitions for
IteratorObject
andAsyncIteratorObject
to be disposable, per the spec:It should be noted that
%IteratorPrototype%
is synonymous withIterator.prototype
per the Iterator Helpers proposal and is represented byIteratorObject
in TypeScript, and that%AsyncIteratorPrototype%
is synonymous withAsyncIterator.prototype
per the Async Iterator Helpers proposal and is represented byAsyncIteratorObject
in TypeScript.Fixes #59263