mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
176 lines
12 KiB
Plaintext
176 lines
12 KiB
Plaintext
//// [tests/cases/compiler/arrayFrom.ts] ////
|
|
|
|
=== arrayFrom.ts ===
|
|
// Tests fix for #20432, ensures Array.from accepts all valid inputs
|
|
// Also tests for #19682
|
|
|
|
interface A {
|
|
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
|
|
|
|
a: string;
|
|
>a : Symbol(A.a, Decl(arrayFrom.ts, 3, 13))
|
|
}
|
|
|
|
interface B {
|
|
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
|
|
|
|
b: string;
|
|
>b : Symbol(B.b, Decl(arrayFrom.ts, 7, 13))
|
|
}
|
|
|
|
const inputA: A[] = [];
|
|
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
|
|
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
|
|
|
|
const inputB: B[] = [];
|
|
>inputB : Symbol(inputB, Decl(arrayFrom.ts, 12, 5))
|
|
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
|
|
|
|
const inputALike: ArrayLike<A> = { length: 0 };
|
|
>inputALike : Symbol(inputALike, Decl(arrayFrom.ts, 13, 5))
|
|
>ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --))
|
|
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
|
|
>length : Symbol(length, Decl(arrayFrom.ts, 13, 34))
|
|
|
|
const inputARand = getEither(inputA, inputALike);
|
|
>inputARand : Symbol(inputARand, Decl(arrayFrom.ts, 14, 5))
|
|
>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<A>();
|
|
>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, 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, --, --))
|
|
>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, --, --))
|
|
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
|
|
|
|
const result2: A[] = Array.from(inputA.values());
|
|
>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, --, --))
|
|
>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, --, --))
|
|
>inputA.values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --))
|
|
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
|
|
>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, 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, --, --))
|
|
>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, --, --))
|
|
>inputA.values : Symbol(Array.values, Decl(lib.es2015.iterable.d.ts, --, --))
|
|
>inputA : Symbol(inputA, Decl(arrayFrom.ts, 11, 5))
|
|
>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, 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, 20, 42))
|
|
>A : Symbol(A, Decl(arrayFrom.ts, 0, 0))
|
|
>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, 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, --, --))
|
|
>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))
|
|
|
|
const result6: B[] = Array.from(inputALike); // expect error
|
|
>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, --, --))
|
|
>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))
|
|
|
|
const result7: B[] = Array.from(inputALike, ({ a }): B => ({ b: a }));
|
|
>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, 23, 46))
|
|
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
|
|
>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, 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, --, --))
|
|
>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))
|
|
|
|
const result9: B[] = Array.from(inputARand, ({ a }): B => ({ b: a }));
|
|
>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, 25, 46))
|
|
>B : Symbol(B, Decl(arrayFrom.ts, 5, 1))
|
|
>b : Symbol(b, Decl(arrayFrom.ts, 25, 60))
|
|
>a : Symbol(a, Decl(arrayFrom.ts, 25, 46))
|
|
|
|
const result10: A[] = Array.from(new Set<A>());
|
|
>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<T>,
|
|
// even when the type is written as : Iterable<T>|ArrayLike<T>
|
|
function getEither<T> (in1: Iterable<T>, in2: ArrayLike<T>) {
|
|
>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, 32, 19))
|
|
>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40))
|
|
>ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --))
|
|
>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, 32, 23))
|
|
>in2 : Symbol(in2, Decl(arrayFrom.ts, 32, 40))
|
|
}
|
|
|