[RFC] Improve core types for (Async) Iterable/Iterator/Generator#3990
[RFC] Improve core types for (Async) Iterable/Iterator/Generator#3990leebyron wants to merge 1 commit intofacebook:mainfrom
Conversation
d3f4ca6 to
cd3d8ba
Compare
* Changes `@@iterator` method to return more specific type in Generators. * An `$Iterator` is an `$Iterable` * Add optional `return` and `throw` methods to `$Iterator` (http://www.ecma-international.org/ecma-262/7.0/#table-54) * A `$Generator` is an `$Iterator` * Fix mistaken function name to `$asyncIterate` to match style of `$iterate`.
cd3d8ba to
e1617b3
Compare
|
@nmote do you think this is ok to merge? |
| interface $Iterator<+Yield,+Return,-Next> extends $Iterable<Yield,Return,Next> { | ||
| @@iterator(): $Iterator<Yield,Return,Next>; | ||
| next(value?: Next): IteratorResult<Yield,Return>; | ||
| +return?: <R>(value: R) => IteratorResult<Yield,R|Return>; |
There was a problem hiding this comment.
A return definition would be great. :)
I'd think it should just be () => IteratorResult<Yield, Return> (same for $AsyncIterator below) as long as that doesn't break passing a generator where an iterator is expected.
If you're hand-writing a return method to handle abrupt completions, you normally wouldn't accept any value because none are passed on IteratorClose. See http://www.ecma-international.org/ecma-262/7.0/#sec-iteratorclose
|
|
||
| interface Generator<+Yield,+Return,-Next> { | ||
| interface $Iterator<+Yield,+Return,-Next> extends $Iterable<Yield,Return,Next> { | ||
| @@iterator(): $Iterator<Yield,Return,Next>; |
There was a problem hiding this comment.
I wish Flow didn't require an @@iterator method on Iterators, even though they typically have one that returns this by convention. (But I'm not sure how to use this without hacks in any case: #1163.)
|
@nmote anything preventing merging this? |
|
Happy comment anniversary @goodmind! I'm also finding lots of issues with async generators, but don't have the OCaml chops to help here. |
|
TIL that there's a convention for
The TS type for |

@@iteratormethod to return more specific type in Generators.$Iteratoris an$Iterablereturnandthrowmethods to$Iterator(http://www.ecma-international.org/ecma-262/7.0/#table-54)$Generatoris an$Iterator$asyncIterateto match style of$iterate.