Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions src/lib/es2015.iterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,15 @@ interface Array<T> {
}

interface ArrayConstructor {
/**
* Creates an array from an iterable object.
* @param iterable An iterable object to convert to an array.
*/
from<T>(iterable: Iterable<T> | ArrayLike<T>): T[];

/**
* Creates an array from an iterable object.
* @param iterable An iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
from<T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[];
from<T extends Iterable<unknown>>(iterable: T): T extends Iterable<infer U> ? U[] : never;
from<T extends Iterable<unknown>, U>(
iterable: T,
mapfn: (v: T extends Iterable<infer V> ? V : never, k: number) => U,
thisArg?: any
): U[];
}


interface ReadonlyArray<T> {
/** Iterator of values in the array. */
[Symbol.iterator](): ArrayIterator<T>;
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/conformance/types/array/fromUnionIterable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @strict: true

type Foo = Iterable<string> | Iterable<number>;
declare const foo: Foo;

const result = Array.from(foo);

type Expected = string[] | number[];
const check: Expected = result;
Loading