From 63f7029b9a8751f96acf72ff3ae29fcf196c32e5 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 2 Nov 2017 17:31:17 -0700 Subject: [PATCH] Add regression tests --- .../reference/intersectionTypeInference3.js | 25 ++++++++ .../intersectionTypeInference3.symbols | 57 +++++++++++++++++ .../intersectionTypeInference3.types | 61 +++++++++++++++++++ .../intersectionTypeInference3.ts | 20 ++++++ 4 files changed, 163 insertions(+) create mode 100644 tests/baselines/reference/intersectionTypeInference3.js create mode 100644 tests/baselines/reference/intersectionTypeInference3.symbols create mode 100644 tests/baselines/reference/intersectionTypeInference3.types create mode 100644 tests/cases/conformance/types/intersection/intersectionTypeInference3.ts diff --git a/tests/baselines/reference/intersectionTypeInference3.js b/tests/baselines/reference/intersectionTypeInference3.js new file mode 100644 index 00000000000..8a7db286ca2 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference3.js @@ -0,0 +1,25 @@ +//// [intersectionTypeInference3.ts] +// Repro from #19682 + +type Nominal = Type & { + [Symbol.species]: Kind; +}; + +type A = Nominal<'A', string>; + +declare const a: Set; +declare const b: Set; + +const c1 = Array.from(a).concat(Array.from(b)); + +// Simpler repro + +declare function from(): T[]; +const c2: ReadonlyArray = from(); + + +//// [intersectionTypeInference3.js] +"use strict"; +// Repro from #19682 +const c1 = Array.from(a).concat(Array.from(b)); +const c2 = from(); diff --git a/tests/baselines/reference/intersectionTypeInference3.symbols b/tests/baselines/reference/intersectionTypeInference3.symbols new file mode 100644 index 00000000000..5b717508319 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference3.symbols @@ -0,0 +1,57 @@ +=== tests/cases/conformance/types/intersection/intersectionTypeInference3.ts === +// Repro from #19682 + +type Nominal = Type & { +>Nominal : Symbol(Nominal, Decl(intersectionTypeInference3.ts, 0, 0)) +>Kind : Symbol(Kind, Decl(intersectionTypeInference3.ts, 2, 13)) +>Type : Symbol(Type, Decl(intersectionTypeInference3.ts, 2, 33)) +>Type : Symbol(Type, Decl(intersectionTypeInference3.ts, 2, 33)) + + [Symbol.species]: Kind; +>Symbol.species : Symbol(SymbolConstructor.species, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --)) +>species : Symbol(SymbolConstructor.species, Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>Kind : Symbol(Kind, Decl(intersectionTypeInference3.ts, 2, 13)) + +}; + +type A = Nominal<'A', string>; +>A : Symbol(A, Decl(intersectionTypeInference3.ts, 4, 2)) +>Nominal : Symbol(Nominal, Decl(intersectionTypeInference3.ts, 0, 0)) + +declare const a: Set; +>a : Symbol(a, Decl(intersectionTypeInference3.ts, 8, 13)) +>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --)) +>A : Symbol(A, Decl(intersectionTypeInference3.ts, 4, 2)) + +declare const b: Set; +>b : Symbol(b, Decl(intersectionTypeInference3.ts, 9, 13)) +>Set : Symbol(Set, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --), Decl(lib.es2015.collection.d.ts, --, --)) +>A : Symbol(A, Decl(intersectionTypeInference3.ts, 4, 2)) + +const c1 = Array.from(a).concat(Array.from(b)); +>c1 : Symbol(c1, Decl(intersectionTypeInference3.ts, 11, 5)) +>Array.from(a).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>a : Symbol(a, Decl(intersectionTypeInference3.ts, 8, 13)) +>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Array.from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>from : Symbol(ArrayConstructor.from, Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>b : Symbol(b, Decl(intersectionTypeInference3.ts, 9, 13)) + +// Simpler repro + +declare function from(): T[]; +>from : Symbol(from, Decl(intersectionTypeInference3.ts, 11, 47)) +>T : Symbol(T, Decl(intersectionTypeInference3.ts, 15, 22)) +>T : Symbol(T, Decl(intersectionTypeInference3.ts, 15, 22)) + +const c2: ReadonlyArray = from(); +>c2 : Symbol(c2, Decl(intersectionTypeInference3.ts, 16, 5)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) +>A : Symbol(A, Decl(intersectionTypeInference3.ts, 4, 2)) +>from : Symbol(from, Decl(intersectionTypeInference3.ts, 11, 47)) + diff --git a/tests/baselines/reference/intersectionTypeInference3.types b/tests/baselines/reference/intersectionTypeInference3.types new file mode 100644 index 00000000000..4d474c84d54 --- /dev/null +++ b/tests/baselines/reference/intersectionTypeInference3.types @@ -0,0 +1,61 @@ +=== tests/cases/conformance/types/intersection/intersectionTypeInference3.ts === +// Repro from #19682 + +type Nominal = Type & { +>Nominal : Nominal +>Kind : Kind +>Type : Type +>Type : Type + + [Symbol.species]: Kind; +>Symbol.species : symbol +>Symbol : SymbolConstructor +>species : symbol +>Kind : Kind + +}; + +type A = Nominal<'A', string>; +>A : Nominal<"A", string> +>Nominal : Nominal + +declare const a: Set; +>a : Set> +>Set : Set +>A : Nominal<"A", string> + +declare const b: Set; +>b : Set> +>Set : Set +>A : Nominal<"A", string> + +const c1 = Array.from(a).concat(Array.from(b)); +>c1 : Nominal<"A", string>[] +>Array.from(a).concat(Array.from(b)) : Nominal<"A", string>[] +>Array.from(a).concat : { (...items: ReadonlyArray>[]): Nominal<"A", string>[]; (...items: (Nominal<"A", string> | ReadonlyArray>)[]): Nominal<"A", string>[]; } +>Array.from(a) : Nominal<"A", string>[] +>Array.from : { (iterable: Iterable, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; (arrayLike: ArrayLike, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; } +>Array : ArrayConstructor +>from : { (iterable: Iterable, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; (arrayLike: ArrayLike, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; } +>a : Set> +>concat : { (...items: ReadonlyArray>[]): Nominal<"A", string>[]; (...items: (Nominal<"A", string> | ReadonlyArray>)[]): Nominal<"A", string>[]; } +>Array.from(b) : Nominal<"A", string>[] +>Array.from : { (iterable: Iterable, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; (arrayLike: ArrayLike, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; } +>Array : ArrayConstructor +>from : { (iterable: Iterable, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; (arrayLike: ArrayLike, mapfn?: ((v: T, k: number) => U) | undefined, thisArg?: any): U[]; } +>b : Set> + +// Simpler repro + +declare function from(): T[]; +>from : () => T[] +>T : T +>T : T + +const c2: ReadonlyArray = from(); +>c2 : ReadonlyArray> +>ReadonlyArray : ReadonlyArray +>A : Nominal<"A", string> +>from() : Nominal<"A", string>[] +>from : () => T[] + diff --git a/tests/cases/conformance/types/intersection/intersectionTypeInference3.ts b/tests/cases/conformance/types/intersection/intersectionTypeInference3.ts new file mode 100644 index 00000000000..ceaff10f7f1 --- /dev/null +++ b/tests/cases/conformance/types/intersection/intersectionTypeInference3.ts @@ -0,0 +1,20 @@ +// @strict: true +// @target: es2015 + +// Repro from #19682 + +type Nominal = Type & { + [Symbol.species]: Kind; +}; + +type A = Nominal<'A', string>; + +declare const a: Set; +declare const b: Set; + +const c1 = Array.from(a).concat(Array.from(b)); + +// Simpler repro + +declare function from(): T[]; +const c2: ReadonlyArray = from();