Skip to content

Commit 6c35abe

Browse files
committed
Add additional Array.from test case
1 parent 68c0e52 commit 6c35abe

File tree

5 files changed

+103
-29
lines changed

5 files changed

+103
-29
lines changed

Diff for: tests/baselines/reference/arrayFrom.errors.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
tests/cases/compiler/arrayFrom.ts(19,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'.
1+
tests/cases/compiler/arrayFrom.ts(20,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'.
22
Type 'A' is not assignable to type 'B'.
33
Property 'b' is missing in type 'A'.
4-
tests/cases/compiler/arrayFrom.ts(22,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'.
4+
tests/cases/compiler/arrayFrom.ts(23,7): error TS2322: Type 'A[]' is not assignable to type 'B[]'.
55

66

77
==== 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
2020
const inputB: B[] = [];
2121
const inputALike: ArrayLike<A> = { length: 0 };
2222
const inputARand = getEither(inputA, inputALike);
23+
const inputASet = new Set<A>();
2324

2425
const result1: A[] = Array.from(inputA);
2526
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
3637
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
3738
const result8: A[] = Array.from(inputARand);
3839
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
40+
const result10: A[] = Array.from(new Set<A>());
41+
const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
3942

4043
// if this is written inline, the compiler seems to infer
4144
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,

Diff for: tests/baselines/reference/arrayFrom.js

+9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const inputA: A[] = [];
1414
const inputB: B[] = [];
1515
const inputALike: ArrayLike<A> = { length: 0 };
1616
const inputARand = getEither(inputA, inputALike);
17+
const inputASet = new Set<A>();
1718

1819
const result1: A[] = Array.from(inputA);
1920
const result2: A[] = Array.from(inputA.values());
@@ -24,6 +25,8 @@ const result6: B[] = Array.from(inputALike); // expect error
2425
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
2526
const result8: A[] = Array.from(inputARand);
2627
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
28+
const result10: A[] = Array.from(new Set<A>());
29+
const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
2730

2831
// if this is written inline, the compiler seems to infer
2932
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
@@ -40,6 +43,7 @@ var inputA = [];
4043
var inputB = [];
4144
var inputALike = { length: 0 };
4245
var inputARand = getEither(inputA, inputALike);
46+
var inputASet = new Set();
4347
var result1 = Array.from(inputA);
4448
var result2 = Array.from(inputA.values());
4549
var result3 = Array.from(inputA.values()); // expect error
@@ -58,6 +62,11 @@ var result9 = Array.from(inputARand, function (_a) {
5862
var a = _a.a;
5963
return ({ b: a });
6064
});
65+
var result10 = Array.from(new Set());
66+
var result11 = Array.from(inputASet, function (_a) {
67+
var a = _a.a;
68+
return ({ b: a });
69+
});
6170
// if this is written inline, the compiler seems to infer
6271
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
6372
// even when the type is written as : Iterable<T>|ArrayLike<T>

Diff for: tests/baselines/reference/arrayFrom.symbols

+53-27
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,25 @@ const inputALike: ArrayLike<A> = { length: 0 };
3232

3333
const inputARand = getEither(inputA, inputALike);
3434
>inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5))
35-
>getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70))
35+
>getEither : Symbol(getEither, Decl(arrayFrom.ts, 27, 70))
3636
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
3737
>inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5))
3838

39+
const inputASet = new Set<A>();
40+
>inputASet : Symbol(inputASet, Decl(arrayFrom.ts, 15, 5))
41+
>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, --, --))
42+
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
43+
3944
const result1: A[] = Array.from(inputA);
40-
>result1 : Symbol(result1, Decl(arrayFrom.ts, 16, 5))
45+
>result1 : Symbol(result1, Decl(arrayFrom.ts, 17, 5))
4146
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
4247
>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, --, --))
4348
>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, --, --))
4449
>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, --, --))
4550
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
4651

4752
const result2: A[] = Array.from(inputA.values());
48-
>result2 : Symbol(result2, Decl(arrayFrom.ts, 17, 5))
53+
>result2 : Symbol(result2, Decl(arrayFrom.ts, 18, 5))
4954
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
5055
>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, --, --))
5156
>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());
5560
>values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --))
5661

5762
const result3: B[] = Array.from(inputA.values()); // expect error
58-
>result3 : Symbol(result3, Decl(arrayFrom.ts, 18, 5))
63+
>result3 : Symbol(result3, Decl(arrayFrom.ts, 19, 5))
5964
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
6065
>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, --, --))
6166
>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,83 +70,104 @@ const result3: B[] = Array.from(inputA.values()); // expect error
6570
>values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --))
6671

6772
const result4: A[] = Array.from(inputB, ({ b }): A => ({ a: b }));
68-
>result4 : Symbol(result4, Decl(arrayFrom.ts, 19, 5))
73+
>result4 : Symbol(result4, Decl(arrayFrom.ts, 20, 5))
6974
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
7075
>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, --, --))
7176
>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, --, --))
7277
>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, --, --))
7378
>inputB : Symbol(inputB, Decl(arrayFrom.ts, 12, 5))
74-
>b : Symbol(b, Decl(arrayFrom.ts, 19, 42))
79+
>b : Symbol(b, Decl(arrayFrom.ts, 20, 42))
7580
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
76-
>a : Symbol(a, Decl(arrayFrom.ts, 19, 56))
77-
>b : Symbol(b, Decl(arrayFrom.ts, 19, 42))
81+
>a : Symbol(a, Decl(arrayFrom.ts, 20, 56))
82+
>b : Symbol(b, Decl(arrayFrom.ts, 20, 42))
7883

7984
const result5: A[] = Array.from(inputALike);
80-
>result5 : Symbol(result5, Decl(arrayFrom.ts, 20, 5))
85+
>result5 : Symbol(result5, Decl(arrayFrom.ts, 21, 5))
8186
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
8287
>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, --, --))
8388
>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, --, --))
8489
>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, --, --))
8590
>inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5))
8691

8792
const result6: B[] = Array.from(inputALike); // expect error
88-
>result6 : Symbol(result6, Decl(arrayFrom.ts, 21, 5))
93+
>result6 : Symbol(result6, Decl(arrayFrom.ts, 22, 5))
8994
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
9095
>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, --, --))
9196
>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, --, --))
9297
>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, --, --))
9398
>inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5))
9499

95100
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
96-
>result7 : Symbol(result7, Decl(arrayFrom.ts, 22, 5))
101+
>result7 : Symbol(result7, Decl(arrayFrom.ts, 23, 5))
97102
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
98103
>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, --, --))
99104
>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, --, --))
100105
>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, --, --))
101106
>inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5))
102-
>a : Symbol(a, Decl(arrayFrom.ts, 22, 46))
107+
>a : Symbol(a, Decl(arrayFrom.ts, 23, 46))
103108
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
104-
>b : Symbol(b, Decl(arrayFrom.ts, 22, 60))
105-
>a : Symbol(a, Decl(arrayFrom.ts, 22, 46))
109+
>b : Symbol(b, Decl(arrayFrom.ts, 23, 60))
110+
>a : Symbol(a, Decl(arrayFrom.ts, 23, 46))
106111

107112
const result8: A[] = Array.from(inputARand);
108-
>result8 : Symbol(result8, Decl(arrayFrom.ts, 23, 5))
113+
>result8 : Symbol(result8, Decl(arrayFrom.ts, 24, 5))
109114
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
110115
>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, --, --))
111116
>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, --, --))
112117
>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, --, --))
113118
>inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5))
114119

115120
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
116-
>result9 : Symbol(result9, Decl(arrayFrom.ts, 24, 5))
121+
>result9 : Symbol(result9, Decl(arrayFrom.ts, 25, 5))
117122
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
118123
>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, --, --))
119124
>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, --, --))
120125
>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, --, --))
121126
>inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5))
122-
>a : Symbol(a, Decl(arrayFrom.ts, 24, 46))
127+
>a : Symbol(a, Decl(arrayFrom.ts, 25, 46))
128+
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
129+
>b : Symbol(b, Decl(arrayFrom.ts, 25, 60))
130+
>a : Symbol(a, Decl(arrayFrom.ts, 25, 46))
131+
132+
const result10: A[] = Array.from(new Set<A>());
133+
>result10 : Symbol(result10, Decl(arrayFrom.ts, 26, 5))
134+
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
135+
>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, --, --))
136+
>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, --, --))
137+
>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, --, --))
138+
>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, --, --))
139+
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
140+
141+
const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
142+
>result11 : Symbol(result11, Decl(arrayFrom.ts, 27, 5))
143+
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
144+
>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, --, --))
145+
>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, --, --))
146+
>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, --, --))
147+
>inputASet : Symbol(inputASet, Decl(arrayFrom.ts, 15, 5))
148+
>a : Symbol(a, Decl(arrayFrom.ts, 27, 46))
123149
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
124-
>b : Symbol(b, Decl(arrayFrom.ts, 24, 60))
125-
>a : Symbol(a, Decl(arrayFrom.ts, 24, 46))
150+
>b : Symbol(b, Decl(arrayFrom.ts, 27, 60))
151+
>a : Symbol(a, Decl(arrayFrom.ts, 27, 46))
126152

127153
// if this is written inline, the compiler seems to infer
128154
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
129155
// even when the type is written as : Iterable<T>|ArrayLike<T>
130156
function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
131-
>getEither : Symbol(getEither, Decl(arrayFrom.ts, 24, 70))
132-
>T : Symbol(T, Decl(arrayFrom.ts, 29, 19))
133-
>in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23))
157+
>getEither : Symbol(getEither, Decl(arrayFrom.ts, 27, 70))
158+
>T : Symbol(T, Decl(arrayFrom.ts, 32, 19))
159+
>in1 : Symbol(in1, Decl(arrayFrom.ts, 32, 23))
134160
>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --))
135-
>T : Symbol(T, Decl(arrayFrom.ts, 29, 19))
136-
>in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40))
161+
>T : Symbol(T, Decl(arrayFrom.ts, 32, 19))
162+
>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40))
137163
>ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --))
138-
>T : Symbol(T, Decl(arrayFrom.ts, 29, 19))
164+
>T : Symbol(T, Decl(arrayFrom.ts, 32, 19))
139165

140166
return Math.random() > 0.5 ? in1 : in2;
141167
>Math.random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
142168
>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, --, --))
143169
>random : Symbol(Math.random, Decl(lib.es5.d.ts, --, --))
144-
>in1 : Symbol(in1, Decl(arrayFrom.ts, 29, 23))
145-
>in2 : Symbol(in2, Decl(arrayFrom.ts, 29, 40))
170+
>in1 : Symbol(in1, Decl(arrayFrom.ts, 32, 23))
171+
>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40))
146172
}
147173

Diff for: tests/baselines/reference/arrayFrom.types

+33
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const inputARand = getEither(inputA, inputALike);
4141
>inputA : A[]
4242
>inputALike : ArrayLike<A>
4343

44+
const inputASet = new Set<A>();
45+
>inputASet : Set<A>
46+
>new Set<A>() : Set<A>
47+
>Set : SetConstructor
48+
>A : A
49+
4450
const result1: A[] = Array.from(inputA);
4551
>result1 : A[]
4652
>A : A
@@ -149,6 +155,33 @@ const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
149155
>b : string
150156
>a : string
151157

158+
const result10: A[] = Array.from(new Set<A>());
159+
>result10 : A[]
160+
>A : A
161+
>Array.from(new Set<A>()) : A[]
162+
>Array.from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
163+
>Array : ArrayConstructor
164+
>from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
165+
>new Set<A>() : Set<A>
166+
>Set : SetConstructor
167+
>A : A
168+
169+
const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
170+
>result11 : B[]
171+
>B : B
172+
>Array.from(inputASet, ({ a }): B => ({ b: a })) : B[]
173+
>Array.from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
174+
>Array : ArrayConstructor
175+
>from : { <T>(arrayLike: ArrayLike<T>): T[]; <T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; <T>(iterable: Iterable<T> | ArrayLike<T>): T[]; <T, U>(iterable: Iterable<T> | ArrayLike<T>, mapfn: (v: T, k: number) => U, thisArg?: any): U[]; }
176+
>inputASet : Set<A>
177+
>({ a }): B => ({ b: a }) : ({ a }: A) => B
178+
>a : string
179+
>B : B
180+
>({ b: a }) : { b: string; }
181+
>{ b: a } : { b: string; }
182+
>b : string
183+
>a : string
184+
152185
// if this is written inline, the compiler seems to infer
153186
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,
154187
// even when the type is written as : Iterable<T>|ArrayLike<T>

Diff for: tests/cases/compiler/arrayFrom.ts

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const inputA: A[] = [];
1515
const inputB: B[] = [];
1616
const inputALike: ArrayLike<A> = { length: 0 };
1717
const inputARand = getEither(inputA, inputALike);
18+
const inputASet = new Set<A>();
1819

1920
const result1: A[] = Array.from(inputA);
2021
const result2: A[] = Array.from(inputA.values());
@@ -25,6 +26,8 @@ const result6: B[] = Array.from(inputALike); // expect error
2526
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
2627
const result8: A[] = Array.from(inputARand);
2728
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
29+
const result10: A[] = Array.from(new Set<A>());
30+
const result11: B[] = Array.from(inputASet, ({ a }): B => ({ b: a }));
2831

2932
// if this is written inline, the compiler seems to infer
3033
// the ?: as always taking the false branch, narrowing to ArrayLike<T>,

0 commit comments

Comments
 (0)