Encountering an error when converting flow code to typescript involving iterators. There seems to be a missing element in the iterator.
const iter: Iterator<RouteData> = contentMap.routes();
const contentArray: Array<RouteData> = Array.from(iter);
The error message specifies an issue with the second line, indicating that iter
is of the correct type or that the return of contentMap.routes()
is indeed an iterator:
Error:(109, 55) TS2769: No overload matches this call.
Overload 1 of 4, '(iterable: Iterable<RouteData> | ArrayLike<RouteData>): RouteData[]', gave the following error.
Argument of type 'Iterator<RouteData, any, undefined>' is not assignable to parameter of type 'Iterable<RouteData> | ArrayLike<RouteData>'.
Property 'length' is missing in type 'Iterator<RouteData, any, undefined>' but required in type 'ArrayLike<RouteData>'.
Overload 2 of 4, '(arrayLike: ArrayLike<RouteData>): RouteData[]', gave the following error.
Argument of type 'Iterator<RouteData, any, undefined>' is not assignable to parameter of type 'ArrayLike<RouteData>'.
Why does this error occur and how can it be resolved?
The iterator is generated as follows:
routes(): Iterator<RouteData> {
return this._routes.values();
}
The compile target for typescript is set to "es6", implying full support for maps. Is it simply impossible to create an array from an iterator, questioning previous practices (and whether babel was more forgiving)?