diff --git a/tests/baselines/reference/arrayFrom.errors.txt b/tests/baselines/reference/arrayFrom.errors.txt index 896125ee1ce..4685ec20db8 100644 --- a/tests/baselines/reference/arrayFrom.errors.txt +++ b/tests/baselines/reference/arrayFrom.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/arrayFrom.ts(19,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. +tests/cases/compiler/arrayFrom.ts(20,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. Type 'A' is not assignable to type 'B'. Property 'b' is missing in type 'A'. -tests/cases/compiler/arrayFrom.ts(22,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. +tests/cases/compiler/arrayFrom.ts(23,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'. ==== tests/cases/compiler/arrayFrom.ts (2 errors) ==== @@ -20,6 +20,7 @@ tests/cases/compiler/arrayFrom.ts(22,7): error TS2322: Type 'A[]' is not assigna const inputB: B[] = []; const inputALike: ArrayLike = { length: 0 }; const inputARand = getEither(inputA, inputALike); + const inputASet = new Set(); const result1: A[] = Array.from(inputA); const result2: A[] = Array.from(inputA.values()); @@ -36,6 +37,8 @@ tests/cases/compiler/arrayFrom.ts(22,7): error TS2322: Type 'A[]' is not assigna const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); const result8: A[] = Array.from(inputARand); const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); + const result10: A[] = Array.from(new Set()); + const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a })); // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike, diff --git a/tests/baselines/reference/arrayFrom.js b/tests/baselines/reference/arrayFrom.js index b9b7ff75268..ea6fcf8fcf0 100644 --- a/tests/baselines/reference/arrayFrom.js +++ b/tests/baselines/reference/arrayFrom.js @@ -14,6 +14,7 @@ const inputA: A[] = []; const inputB: B[] = []; const inputALike: ArrayLike = { length: 0 }; const inputARand = getEither(inputA, inputALike); +const inputASet = new Set(); const result1: A[] = Array.from(inputA); const result2: A[] = Array.from(inputA.values()); @@ -24,6 +25,8 @@ const result6: B[] = Array.from(inputALike); // expect error const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); const result8: A[] = Array.from(inputARand); const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); +const result10: A[] = Array.from(new Set()); +const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a })); // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike, @@ -40,6 +43,7 @@ var inputA = []; var inputB = []; var inputALike = { length: 0 }; var inputARand = getEither(inputA, inputALike); +var inputASet = new Set(); var result1 = Array.from(inputA); var result2 = Array.from(inputA.values()); var result3 = Array.from(inputA.values()); // expect error @@ -58,6 +62,11 @@ var result9 = Array.from(inputARand, function (_a) { var a = _a.a; return ({ b: a }); }); +var result10 = Array.from(new Set()); +var result11 = Array.from(inputASet, function (_a) { + var a = _a.a; + return ({ b: a }); +}); // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike, // even when the type is written as : Iterable|ArrayLike diff --git a/tests/baselines/reference/arrayFrom.symbols b/tests/baselines/reference/arrayFrom.symbols index 895b648a2a3..29ccb93a2e6 100644 --- a/tests/baselines/reference/arrayFrom.symbols +++ b/tests/baselines/reference/arrayFrom.symbols @@ -32,12 +32,17 @@ const inputALike: ArrayLike = { length: 0 }; const inputARand = getEither(inputA, inputALike); >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) ->getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70)) +>getEither : Symbol(getEither, Decl(arrayFrom.ts, 27, 70)) >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) +const inputASet = new Set(); +>inputASet : Symbol(inputASet, Decl(arrayFrom.ts, 15, 5)) +>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) + const result1: A[] = Array.from(inputA); ->result1 : Symbol(result1, Decl(arrayFrom.ts, 16, 5)) +>result1 : Symbol(result1, Decl(arrayFrom.ts, 17, 5)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -45,7 +50,7 @@ const result1: A[] = Array.from(inputA); >inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5)) const result2: A[] = Array.from(inputA.values()); ->result2 : Symbol(result2, Decl(arrayFrom.ts, 17, 5)) +>result2 : Symbol(result2, Decl(arrayFrom.ts, 18, 5)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -55,7 +60,7 @@ const result2: A[] = Array.from(inputA.values()); >values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) const result3: B[] = Array.from(inputA.values()); // expect error ->result3 : Symbol(result3, Decl(arrayFrom.ts, 18, 5)) +>result3 : Symbol(result3, Decl(arrayFrom.ts, 19, 5)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -65,19 +70,19 @@ const result3: B[] = Array.from(inputA.values()); // expect error >values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --)) const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b })); ->result4 : Symbol(result4, Decl(arrayFrom.ts, 19, 5)) +>result4 : Symbol(result4, Decl(arrayFrom.ts, 20, 5)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >inputB : Symbol(inputB, Decl(arrayFrom.ts, 12, 5)) ->b : Symbol(b, Decl(arrayFrom.ts, 19, 42)) +>b : Symbol(b, Decl(arrayFrom.ts, 20, 42)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) ->a : Symbol(a, Decl(arrayFrom.ts, 19, 56)) ->b : Symbol(b, Decl(arrayFrom.ts, 19, 42)) +>a : Symbol(a, Decl(arrayFrom.ts, 20, 56)) +>b : Symbol(b, Decl(arrayFrom.ts, 20, 42)) const result5: A[] = Array.from(inputALike); ->result5 : Symbol(result5, Decl(arrayFrom.ts, 20, 5)) +>result5 : Symbol(result5, Decl(arrayFrom.ts, 21, 5)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -85,7 +90,7 @@ const result5: A[] = Array.from(inputALike); >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) const result6: B[] = Array.from(inputALike); // expect error ->result6 : Symbol(result6, Decl(arrayFrom.ts, 21, 5)) +>result6 : Symbol(result6, Decl(arrayFrom.ts, 22, 5)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -93,19 +98,19 @@ const result6: B[] = Array.from(inputALike); // expect error >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); ->result7 : Symbol(result7, Decl(arrayFrom.ts, 22, 5)) +>result7 : Symbol(result7, Decl(arrayFrom.ts, 23, 5)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5)) ->a : Symbol(a, Decl(arrayFrom.ts, 22, 46)) +>a : Symbol(a, Decl(arrayFrom.ts, 23, 46)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) ->b : Symbol(b, Decl(arrayFrom.ts, 22, 60)) ->a : Symbol(a, Decl(arrayFrom.ts, 22, 46)) +>b : Symbol(b, Decl(arrayFrom.ts, 23, 60)) +>a : Symbol(a, Decl(arrayFrom.ts, 23, 46)) const result8: A[] = Array.from(inputARand); ->result8 : Symbol(result8, Decl(arrayFrom.ts, 23, 5)) +>result8 : Symbol(result8, Decl(arrayFrom.ts, 24, 5)) >A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) @@ -113,35 +118,56 @@ const result8: A[] = Array.from(inputARand); >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); ->result9 : Symbol(result9, Decl(arrayFrom.ts, 24, 5)) +>result9 : Symbol(result9, Decl(arrayFrom.ts, 25, 5)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) >Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5)) ->a : Symbol(a, Decl(arrayFrom.ts, 24, 46)) +>a : Symbol(a, Decl(arrayFrom.ts, 25, 46)) >B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) ->b : Symbol(b, Decl(arrayFrom.ts, 24, 60)) ->a : Symbol(a, Decl(arrayFrom.ts, 24, 46)) +>b : Symbol(b, Decl(arrayFrom.ts, 25, 60)) +>a : Symbol(a, Decl(arrayFrom.ts, 25, 46)) + +const result10: A[] = Array.from(new Set()); +>result10 : Symbol(result10, Decl(arrayFrom.ts, 26, 5)) +>A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) +>Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Set : Symbol(Set, Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>A : Symbol(A, Decl(arrayFrom.ts, 0, 0)) + +const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a })); +>result11 : Symbol(result11, Decl(arrayFrom.ts, 27, 5)) +>B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) +>Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>from : Symbol(ArrayConstructor.from, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>inputASet : Symbol(inputASet, Decl(arrayFrom.ts, 15, 5)) +>a : Symbol(a, Decl(arrayFrom.ts, 27, 46)) +>B : Symbol(B, Decl(arrayFrom.ts, 5, 1)) +>b : Symbol(b, Decl(arrayFrom.ts, 27, 60)) +>a : Symbol(a, Decl(arrayFrom.ts, 27, 46)) // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike, // even when the type is written as : Iterable|ArrayLike function getEither (in1: Iterable, in2: ArrayLike) { ->getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70)) ->T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) ->in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23)) +>getEither : Symbol(getEither, Decl(arrayFrom.ts, 27, 70)) +>T : Symbol(T, Decl(arrayFrom.ts, 32, 19)) +>in1 : Symbol(in1, Decl(arrayFrom.ts, 32, 23)) >Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) ->T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) ->in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40)) +>T : Symbol(T, Decl(arrayFrom.ts, 32, 19)) +>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40)) >ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(arrayFrom.ts, 29, 19)) +>T : Symbol(T, Decl(arrayFrom.ts, 32, 19)) return Math.random() > 0.5 ? in1 : in2; >Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) >Math : Symbol(Math, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) >random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --)) ->in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23)) ->in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40)) +>in1 : Symbol(in1, Decl(arrayFrom.ts, 32, 23)) +>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40)) } diff --git a/tests/baselines/reference/arrayFrom.types b/tests/baselines/reference/arrayFrom.types index b833fd0dc01..870d3dde945 100644 --- a/tests/baselines/reference/arrayFrom.types +++ b/tests/baselines/reference/arrayFrom.types @@ -41,6 +41,12 @@ const inputARand = getEither(inputA, inputALike); >inputA : A[] >inputALike : ArrayLike +const inputASet = new Set(); +>inputASet : Set +>new Set() : Set +>Set : SetConstructor +>A : A + const result1: A[] = Array.from(inputA); >result1 : A[] >A : A @@ -149,6 +155,33 @@ const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); >b : string >a : string +const result10: A[] = Array.from(new Set()); +>result10 : A[] +>A : A +>Array.from(new Set()) : A[] +>Array.from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; } +>Array : ArrayConstructor +>from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; } +>new Set() : Set +>Set : SetConstructor +>A : A + +const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a })); +>result11 : B[] +>B : B +>Array.from(inputASet, ({ a }): B => ({ b: a })) : B[] +>Array.from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; } +>Array : ArrayConstructor +>from : { (arrayLike: ArrayLike): T[]; (arrayLike: ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; (iterable: Iterable | ArrayLike): T[]; (iterable: Iterable | ArrayLike, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; } +>inputASet : Set +>({ a }): B => ({ b: a }) : ({ a }: A) => B +>a : string +>B : B +>({ b: a }) : { b: string; } +>{ b: a } : { b: string; } +>b : string +>a : string + // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike, // even when the type is written as : Iterable|ArrayLike diff --git a/tests/cases/compiler/arrayFrom.ts b/tests/cases/compiler/arrayFrom.ts index f0b8f5928cb..57b76943a02 100644 --- a/tests/cases/compiler/arrayFrom.ts +++ b/tests/cases/compiler/arrayFrom.ts @@ -15,6 +15,7 @@ const inputA: A[] = []; const inputB: B[] = []; const inputALike: ArrayLike = { length: 0 }; const inputARand = getEither(inputA, inputALike); +const inputASet = new Set(); const result1: A[] = Array.from(inputA); const result2: A[] = Array.from(inputA.values()); @@ -25,6 +26,8 @@ const result6: B[] = Array.from(inputALike); // expect error const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a })); const result8: A[] = Array.from(inputARand); const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a })); +const result10: A[] = Array.from(new Set()); +const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a })); // if this is written inline, the compiler seems to infer // the ?: as always taking the false branch, narrowing to ArrayLike,