From 027fe217c1547c8080f1a15a775ce6d8065ef2ab Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 17 Dec 2020 06:52:42 -1000 Subject: [PATCH] Add regression tests --- .../cases/compiler/strictSubtypeReduction.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/cases/compiler/strictSubtypeReduction.ts diff --git a/tests/cases/compiler/strictSubtypeReduction.ts b/tests/cases/compiler/strictSubtypeReduction.ts new file mode 100644 index 00000000000..9323e3deca7 --- /dev/null +++ b/tests/cases/compiler/strictSubtypeReduction.ts @@ -0,0 +1,34 @@ +// @strict: true + +// Repro from #41977 + +class S1 { + static f(a: number | string): void {} +} + +class S2 { + static f(a: number): void {} + static g(a: number): void {} +} + +function f(a: number): void {} +function g(a: number): void {} + +// Declaring the following type aliases should have no effect + +type T1 = typeof S2.g; +type T2 = typeof g; + +// All should have type ((a: number) => void)[] + +const y1 = [S1.f, f]; +const y2 = [S1.f, g]; +const y3 = [S1.f, S2.f]; +const y4 = [S1.f, S2.g]; + +// All assignments should be errors + +const x1: ((ctrl: number | string) => void)[] = y1; +const x2: ((ctrl: number | string) => void)[] = y2; +const x3: ((ctrl: number | string) => void)[] = y3; +const x4: ((ctrl: number | string) => void)[] = y4;