diff --git a/lib/core.js b/lib/core.js index 5dda9cd089a..3bf5cc93285 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1753,6 +1753,16 @@ interface $Iterable<+Yield,+Return,-Next> { } type Iterable<+T> = $Iterable; +interface IteratorConstructor { + /** + * This method allows wrapping "iterator-like" objects with an iterator. + * @returns The argument object if it's already an iterator, or a wrapping iterator if the passed object implements a callable @@iterator property. + */ + from<+Yield,+Return,-Next>(source: $Iterable): $Iterator; + } + +declare var Iterator: IteratorConstructor; + interface Generator<+Yield,+Return,-Next> { @@iterator(): $Iterator; next(value?: Next): IteratorResult; diff --git a/tests/iterator_helpers/.flowconfig b/tests/iterator_helpers/.flowconfig new file mode 100644 index 00000000000..6a52ce2dabb --- /dev/null +++ b/tests/iterator_helpers/.flowconfig @@ -0,0 +1,3 @@ +[options] +no_flowlib=false +all=true diff --git a/tests/iterator_helpers/from.js b/tests/iterator_helpers/from.js new file mode 100644 index 00000000000..ea11945e34c --- /dev/null +++ b/tests/iterator_helpers/from.js @@ -0,0 +1,2 @@ +/* @flow */ +(Iterator.from([1]): Iterator); diff --git a/tests/iterator_helpers/iterator_helpers.exp b/tests/iterator_helpers/iterator_helpers.exp new file mode 100644 index 00000000000..2829d581f51 --- /dev/null +++ b/tests/iterator_helpers/iterator_helpers.exp @@ -0,0 +1 @@ +Found 0 errors