Skip to content

Iterator Helpers Typing #59908

@nikolaybotev

Description

@nikolaybotev

⚙ Compilation target

ESNext

⚙ Library

lib.esnext.d.ts

Missing / Incorrect Definition

global Iterator class

Sample Code

Iterator.from([1, 2, 3, 4, 5])
  .map(n => n + 1)
  .filter(n => n > 2)
  .drop(1)
  .take(2)
  .toArray() // [4, 5]

See also all the validation tests (working since Node.js 22.0.0) at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator#iterator_helpers

However, the following code should (ideally) continue working:

const customIterator: Iterator<number> = { next: () => ({ value: 42 }) };

Documentation Link

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    close