From 8af1dca33db4260ec6cc50781daf75055c352124 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Tue, 15 Oct 2019 13:09:13 -0700 Subject: [PATCH] Add tests --- .../reference/correctOrderOfPromiseMethod.js | 8 +++- .../correctOrderOfPromiseMethod.symbols | 12 ++++- .../correctOrderOfPromiseMethod.types | 20 ++++++--- .../reference/typeInferenceWithTupleType.js | 12 +++++ .../typeInferenceWithTupleType.symbols | 44 +++++++++++++++++++ .../typeInferenceWithTupleType.types | 29 ++++++++++++ .../compiler/correctOrderOfPromiseMethod.ts | 6 ++- .../types/tuple/typeInferenceWithTupleType.ts | 11 ++++- 8 files changed, 133 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.js b/tests/baselines/reference/correctOrderOfPromiseMethod.js index fadda95374f3e..ef8c03670f8ea 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.js +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.js @@ -15,7 +15,7 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ providerA(), providerB(), - ] as const); + ]); const dataA: A[] = resultA; const dataB: B[] = resultB; @@ -24,6 +24,10 @@ async function countEverything(): Promise { } return 0; } + +// #31179 + +const expected: Promise<['a', 'b', 'c']> = Promise.all(undefined as readonly ['a', 'b', 'c']); //// [correctOrderOfPromiseMethod.js] @@ -92,3 +96,5 @@ function countEverything() { }); }); } +// #31179 +var expected = Promise.all(undefined); diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols index 1e67e9444c67f..e2e4116b9a5cd 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.symbols +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.symbols @@ -43,7 +43,7 @@ async function countEverything(): Promise { providerB(), >providerB : Symbol(providerB, Decl(correctOrderOfPromiseMethod.ts, 11, 9)) - ] as const); + ]); const dataA: A[] = resultA; >dataA : Symbol(dataA, Decl(correctOrderOfPromiseMethod.ts, 18, 9)) @@ -70,3 +70,13 @@ async function countEverything(): Promise { return 0; } +// #31179 + +const expected: Promise<['a', 'b', 'c']> = Promise.all(undefined as readonly ['a', 'b', 'c']); +>expected : Symbol(expected, Decl(correctOrderOfPromiseMethod.ts, 28, 5)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Promise.all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>all : Symbol(PromiseConstructor.all, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --) ... and 6 more) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/correctOrderOfPromiseMethod.types b/tests/baselines/reference/correctOrderOfPromiseMethod.types index a6f2c46782e0a..601dd2c7c9fed 100644 --- a/tests/baselines/reference/correctOrderOfPromiseMethod.types +++ b/tests/baselines/reference/correctOrderOfPromiseMethod.types @@ -28,13 +28,12 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ >resultA : A[] >resultB : B[] ->await Promise.all([ providerA(), providerB(), ] as const) : [A[], B[]] ->Promise.all([ providerA(), providerB(), ] as const) : Promise<[A[], B[]]> +>await Promise.all([ providerA(), providerB(), ]) : [A[], B[]] +>Promise.all([ providerA(), providerB(), ]) : Promise<[A[], B[]]> >Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } >Promise : PromiseConstructor >all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } ->[ providerA(), providerB(), ] as const : readonly [Promise, Promise] ->[ providerA(), providerB(), ] : readonly [Promise, Promise] +>[ providerA(), providerB(), ] : [Promise, Promise] providerA(), >providerA() : Promise @@ -44,7 +43,7 @@ async function countEverything(): Promise { >providerB() : Promise >providerB : () => Promise - ] as const); + ]); const dataA: A[] = resultA; >dataA : A[] @@ -72,3 +71,14 @@ async function countEverything(): Promise { >0 : 0 } +// #31179 + +const expected: Promise<['a', 'b', 'c']> = Promise.all(undefined as readonly ['a', 'b', 'c']); +>expected : Promise<["a", "b", "c"]> +>Promise.all(undefined as readonly ['a', 'b', 'c']) : Promise<["a", "b", "c"]> +>Promise.all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>Promise : PromiseConstructor +>all : { (values: Iterable>): Promise; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike, T10 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike, T9 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8, T9]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike, T8 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7, T8]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike, T7 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6, T7]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike, T6 | PromiseLike]): Promise<[T1, T2, T3, T4, T5, T6]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike, T5 | PromiseLike]): Promise<[T1, T2, T3, T4, T5]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike, T4 | PromiseLike]): Promise<[T1, T2, T3, T4]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike, T3 | PromiseLike]): Promise<[T1, T2, T3]>; (values: readonly [T1 | PromiseLike, T2 | PromiseLike]): Promise<[T1, T2]>; (values: readonly (T | PromiseLike)[]): Promise; } +>undefined as readonly ['a', 'b', 'c'] : readonly ["a", "b", "c"] +>undefined : undefined + diff --git a/tests/baselines/reference/typeInferenceWithTupleType.js b/tests/baselines/reference/typeInferenceWithTupleType.js index 10a18274c73dd..b2349d624cad7 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.js +++ b/tests/baselines/reference/typeInferenceWithTupleType.js @@ -23,6 +23,15 @@ var zipResult = zip(["foo", "bar"], [5, 6]); var zipResultEle = zipResult[0]; // [string, number] var zipResultEleEle = zipResult[0][0]; // string +// #33559 and #33752 + +interface I {} +declare function f1(values: [I, I]): T1; +declare function f2(values: readonly [I, I]): T1; + +let expected: 'a'; +expected = f1(undefined as [I<'a'>, I<'b'>]); +expected = f2(undefined as [I<'a'>, I<'b'>]); //// [typeInferenceWithTupleType.js] @@ -46,3 +55,6 @@ function zip(array1, array2) { var zipResult = zip(["foo", "bar"], [5, 6]); var zipResultEle = zipResult[0]; // [string, number] var zipResultEleEle = zipResult[0][0]; // string +var expected; +expected = f1(undefined); +expected = f2(undefined); diff --git a/tests/baselines/reference/typeInferenceWithTupleType.symbols b/tests/baselines/reference/typeInferenceWithTupleType.symbols index 040e7bed1b10b..9995806a2437c 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.symbols +++ b/tests/baselines/reference/typeInferenceWithTupleType.symbols @@ -97,4 +97,48 @@ var zipResultEleEle = zipResult[0][0]; // string >0 : Symbol(0) >0 : Symbol(0) +// #33559 and #33752 + +interface I {} +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>T : Symbol(T, Decl(typeInferenceWithTupleType.ts, 26, 12)) + +declare function f1(values: [I, I]): T1; +>f1 : Symbol(f1, Decl(typeInferenceWithTupleType.ts, 26, 17)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 27, 20)) +>T2 : Symbol(T2, Decl(typeInferenceWithTupleType.ts, 27, 23)) +>values : Symbol(values, Decl(typeInferenceWithTupleType.ts, 27, 28)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 27, 20)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>T2 : Symbol(T2, Decl(typeInferenceWithTupleType.ts, 27, 23)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 27, 20)) + +declare function f2(values: readonly [I, I]): T1; +>f2 : Symbol(f2, Decl(typeInferenceWithTupleType.ts, 27, 56)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 28, 20)) +>T2 : Symbol(T2, Decl(typeInferenceWithTupleType.ts, 28, 23)) +>values : Symbol(values, Decl(typeInferenceWithTupleType.ts, 28, 28)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 28, 20)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>T2 : Symbol(T2, Decl(typeInferenceWithTupleType.ts, 28, 23)) +>T1 : Symbol(T1, Decl(typeInferenceWithTupleType.ts, 28, 20)) + +let expected: 'a'; +>expected : Symbol(expected, Decl(typeInferenceWithTupleType.ts, 30, 3)) + +expected = f1(undefined as [I<'a'>, I<'b'>]); +>expected : Symbol(expected, Decl(typeInferenceWithTupleType.ts, 30, 3)) +>f1 : Symbol(f1, Decl(typeInferenceWithTupleType.ts, 26, 17)) +>undefined : Symbol(undefined) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) + +expected = f2(undefined as [I<'a'>, I<'b'>]); +>expected : Symbol(expected, Decl(typeInferenceWithTupleType.ts, 30, 3)) +>f2 : Symbol(f2, Decl(typeInferenceWithTupleType.ts, 27, 56)) +>undefined : Symbol(undefined) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) +>I : Symbol(I, Decl(typeInferenceWithTupleType.ts, 22, 38)) diff --git a/tests/baselines/reference/typeInferenceWithTupleType.types b/tests/baselines/reference/typeInferenceWithTupleType.types index 4e407964bb0df..7e6986df223a9 100644 --- a/tests/baselines/reference/typeInferenceWithTupleType.types +++ b/tests/baselines/reference/typeInferenceWithTupleType.types @@ -109,4 +109,33 @@ var zipResultEleEle = zipResult[0][0]; // string >0 : 0 >0 : 0 +// #33559 and #33752 + +interface I {} +declare function f1(values: [I, I]): T1; +>f1 : (values: [I, I]) => T1 +>values : [I, I] + +declare function f2(values: readonly [I, I]): T1; +>f2 : (values: readonly [I, I]) => T1 +>values : readonly [I, I] + +let expected: 'a'; +>expected : "a" + +expected = f1(undefined as [I<'a'>, I<'b'>]); +>expected = f1(undefined as [I<'a'>, I<'b'>]) : "a" +>expected : "a" +>f1(undefined as [I<'a'>, I<'b'>]) : "a" +>f1 : (values: [I, I]) => T1 +>undefined as [I<'a'>, I<'b'>] : [I<"a">, I<"b">] +>undefined : undefined + +expected = f2(undefined as [I<'a'>, I<'b'>]); +>expected = f2(undefined as [I<'a'>, I<'b'>]) : "a" +>expected : "a" +>f2(undefined as [I<'a'>, I<'b'>]) : "a" +>f2 : (values: readonly [I, I]) => T1 +>undefined as [I<'a'>, I<'b'>] : [I<"a">, I<"b">] +>undefined : undefined diff --git a/tests/cases/compiler/correctOrderOfPromiseMethod.ts b/tests/cases/compiler/correctOrderOfPromiseMethod.ts index 70c730c6b20b1..3ce83eb3dd840 100644 --- a/tests/cases/compiler/correctOrderOfPromiseMethod.ts +++ b/tests/cases/compiler/correctOrderOfPromiseMethod.ts @@ -17,7 +17,7 @@ async function countEverything(): Promise { const [resultA, resultB] = await Promise.all([ providerA(), providerB(), - ] as const); + ]); const dataA: A[] = resultA; const dataB: B[] = resultB; @@ -26,3 +26,7 @@ async function countEverything(): Promise { } return 0; } + +// #31179 + +const expected: Promise<['a', 'b', 'c']> = Promise.all(undefined as readonly ['a', 'b', 'c']); diff --git a/tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts b/tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts index d19353d29ef02..4ef6672796229 100644 --- a/tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts +++ b/tests/cases/conformance/types/tuple/typeInferenceWithTupleType.ts @@ -1,4 +1,4 @@ -function combine(x: T, y: U): [T, U] { +function combine(x: T, y: U): [T, U] { return [x, y]; } @@ -22,3 +22,12 @@ var zipResult = zip(["foo", "bar"], [5, 6]); var zipResultEle = zipResult[0]; // [string, number] var zipResultEleEle = zipResult[0][0]; // string +// #33559 and #33752 + +interface I {} +declare function f1(values: [I, I]): T1; +declare function f2(values: readonly [I, I]): T1; + +let expected: 'a'; +expected = f1(undefined as [I<'a'>, I<'b'>]); +expected = f2(undefined as [I<'a'>, I<'b'>]);