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

fix(cli/js/net): Make generator return types iterable #4661

Merged
merged 3 commits into from
Apr 15, 2020

Conversation

nayeemrmn
Copy link
Collaborator

Strengthens the type so this doesn't throw a type error:

const iterator = Deno.listen({ port: 10000 })[Symbol.asyncIterator]();
for await (const n of iterator);

i.e the iterators are also iterable.

@ry
Copy link
Member

ry commented Apr 7, 2020

I don't really understand. Why would you want to do that?

@nayeemrmn
Copy link
Collaborator Author

That's how generators are defined everywhere else, this was a mistake. Generators provide this property but those type defs are hiding it. If it really needs a use case, I suppose there is a different behaviour for two loops sharing the same iterator object which might be useful to someone.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how generators are defined everywhere else, this was a mistake. Generators provide this property but those type defs are hiding it. If it really needs a use case, I suppose there is a different behaviour for two loops sharing the same iterator object which might be useful to someone.

This type declaration confirms that:
https:/microsoft/TypeScript/blob/712967b2780e8ecd28f8f1e2e89c1ebd2592bb4c/lib/lib.es2018.asynciterable.d.ts#L32-L45

LGTM

@bartlomieju bartlomieju merged commit 95eb6d7 into denoland:master Apr 15, 2020
@nayeemrmn nayeemrmn deleted the net-iterables branch April 15, 2020 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants