From cc817bc63efb649a46d0ae9cdfba1786474b9734 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Sun, 13 Oct 2019 09:45:56 -0700 Subject: [PATCH] Add tests --- tests/cases/compiler/reachabilityChecks4.ts | 53 ++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/cases/compiler/reachabilityChecks4.ts b/tests/cases/compiler/reachabilityChecks4.ts index f07395ac38e..a853a6e996a 100644 --- a/tests/cases/compiler/reachabilityChecks4.ts +++ b/tests/cases/compiler/reachabilityChecks4.ts @@ -12,4 +12,55 @@ function foo(x, y) { case 4: return 3; } -} \ No newline at end of file +} + +declare function noop(): void; +declare function fail(): never; + +function f1(x: 0 | 1 | 2) { + switch (x) { + case 0: + fail(); + case 1: + noop(); + case 2: + return; + } +} + +// Repro from #34021 + +type Behavior = 'SLIDE' | 'SLIDE_OUT' +type Direction = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM' + +interface Transition { + behavior: Behavior + direction: Direction +} + +function f2(transition: Transition): any { + switch (transition.behavior) { + case 'SLIDE': + switch (transition.direction) { + case 'LEFT': + return [] + case 'RIGHT': + return [] + case 'TOP': + return [] + case 'BOTTOM': + return [] + } + case 'SLIDE_OUT': + switch (transition.direction) { + case 'LEFT': + return [] + case 'RIGHT': + return [] + case 'TOP': + return [] + case 'BOTTOM': + return [] + } + } +}