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

[Bug] Typing issue causes AsyncIterator.from(...) to fail against plain ES iterator-like things #21

Closed
bytenik opened this issue Apr 10, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@bytenik
Copy link

bytenik commented Apr 10, 2024

To describe the bug by way of an example, I am using the Repeater library which contains a class, Repeater. Repeater is not a subclass of AsyncIterator, but it is iterator-like in a way that is duck-type compatible with iterators and can be for async ...'d and etc. However, Repeater does not implement the iterator helpers since it is an implementation of an ECMAScript iterator and without the stage3 helpers.

When I do AsyncIterator.from(...) on a Repeater to then be able to use the iterator helpers on the resulting iterator, I get:

Argument of type 'Repeater<ElementType, any, unknown>' is not assignable to parameter of type '_AsyncIteratorLike<ElementType, any, undefined>'.
  Type 'Repeater<ElementType, any, unknown>' is missing the following properties from type 'AsyncIterator<ElementType, any, undefined>': map, filter, asIndexedPairs, take, and 43 more.ts(2345)

This is because the typing for AsyncIterator expects an iterator "enhanced" by this polyfill. I suggest making an AsyncIteratorLike and IteratorLike that include only the bare minimum items to support AsyncIterator.from and Iterator.from respectively, which would include only the original ES mainline characteristics.

@bytenik bytenik added the bug Something isn't working label Apr 10, 2024
MadProbe added a commit that referenced this issue Apr 14, 2024
Improves typing & spec compliance
fixes: [Bug] Typing issue causes AsyncIterator.from(...) to fail against plain ES iterator-like things #21
fixes: [Bug] counter/index argument is not provided to callback functions #22
@MadProbe
Copy link
Owner

This has been fixed in version 3.0.0. Thank you for reporting this bug!
This was an oversight from me and I have fixed this not only in (Async)Iterator.from, but in other methods as well, like .flatMap, .flatten, .zip, and others.

@bytenik
Copy link
Author

bytenik commented Apr 18, 2024

Thank you!

@MadProbe
Copy link
Owner

I have made one dumb mistake not defining in iterable-likes Symbol.iterator as a function but as a regular property.
So please update to 3.0.1.
I am sorry for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants