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

Iterator and AsyncIterator missing Symbol.dispose method in esnext.disposable #59263

Closed
jsonnull opened this issue Jul 13, 2024 · 1 comment · Fixed by #59633
Closed

Iterator and AsyncIterator missing Symbol.dispose method in esnext.disposable #59263

jsonnull opened this issue Jul 13, 2024 · 1 comment · Fixed by #59633
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this

Comments

@jsonnull
Copy link

jsonnull commented Jul 13, 2024

⚙ Compilation target

ESNext

⚙ Library

esnext.disposable

Missing / Incorrect Definition

Iterator and AsyncIterator are missing types for Symbol.dispose method.

Sample Code

function* myIterable() {
  using stack = new DisposableStack();
  stack.defer(console.log('cleanup'));

  yield 1;
  yield 2;
  yield 3;
}

{
  using iter = myIterable();
  //           ^^^^^^^^^^ error
  iter.next();
}
The initializer of a 'using' declaration must be either an object with a '[Symbol.dispose]()' method, or be 'null' or 'undefined'.
  Property '[Symbol.dispose]' is missing in type 'Generator<number, void, void>' but required in type 'Disposable'.ts(2850)
lib.esnext.disposable.d.ts(34, 5): '[Symbol.dispose]' is declared here.

Documentation Link

The proposal lists these extensions:

core-js implementation of the proposal includes the new built-ins:

@jsonnull jsonnull changed the title Iterable and AsyncIterable missing Symbol.dispose method in esnext.disposable Iterator and AsyncIterator missing Symbol.dispose method in esnext.disposable Jul 13, 2024
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Jul 26, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Jul 26, 2024
@rbuckton
Copy link
Member

These will need to be added to the new BuiltinIterator and BuiltinAsyncIterator, as [Symbol.dispose] and [Symbol.asyncDispose] are only present by default on built-in iterators and generators. They don't need to be added to Iterator or AsyncIterator as they are not requirements for the iterator protocol itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
4 participants