Skip to content

Add support for Iterator Helpers (now stage 3) #59568

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

Closed
thesoftwarephilosopher opened this issue Aug 9, 2024 · 7 comments
Closed

Add support for Iterator Helpers (now stage 3) #59568

thesoftwarephilosopher opened this issue Aug 9, 2024 · 7 comments
Labels
Duplicate An existing issue was already created

Comments

@thesoftwarephilosopher
Copy link

⚙ Compilation target

ESNext

⚙ Library

n/a

Missing / Incorrect Definition

IterableIterator should have map/filter/etc.

Sample Code

// Tested in both Node 22 and latest Edge

const m = new Map([[1, 2], [3, 4]]);
const keys = m.keys(); // IterableIterator<number>
const iter = keys.map(n => n * 100);
// Property 'map' does not exist on type 'IterableIterator<number>'.ts(2339)

const val = iter.next();
console.log(val);
// {value: 100, done: false}

Documentation Link

@xiBread
Copy link

xiBread commented Aug 9, 2024

Already added in #58222

@jakebailey
Copy link
Member

jakebailey commented Aug 9, 2024

Yep: https://devblogs.microsoft.com/typescript/announcing-typescript-5-6-beta/#iterator-helper-methods

Playground Link

@jakebailey jakebailey added the Duplicate An existing issue was already created label Aug 9, 2024
@thesoftwarephilosopher
Copy link
Author

Ah I thought I saw this somewhere. Thanks guys.

@thesoftwarephilosopher
Copy link
Author

Why do those docs say

and for some reason reduce

? Like, is reduce known to be useless in lazy iterators or something?

@RyanCavanaugh
Copy link
Member

I have no idea lol. @DanielRosenwasser ?

@DanielRosenwasser
Copy link
Member

It was just a playful dig at the method. reduce can be useful but unfortunately I find most uses of it are super inefficient, are just a bad forEach, or overly clever. You can feel free to use reduce and I won't judge you. 😄

@thesoftwarephilosopher
Copy link
Author

thesoftwarephilosopher commented Aug 9, 2024

True, come to think of it, I can't remember how many years it's been since I actually used reduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

5 participants