TypeScript/tests/baselines/reference/reachabilityChecks4.types
2019-10-13 09:46:02 -07:00

162 lines
2.6 KiB
Plaintext

=== tests/cases/compiler/reachabilityChecks4.ts ===
function foo(x, y) {
>foo : (x: any, y: any) => 1 | 2 | 3
>x : any
>y : any
switch (x) {
>x : any
case 1:
>1 : 1
case 2:
>2 : 2
return 1;
>1 : 1
case 3:
>3 : 3
if (y) {
>y : any
return 2;
>2 : 2
}
case 4:
>4 : 4
return 3;
>3 : 3
}
}
declare function noop(): void;
>noop : () => void
declare function fail(): never;
>fail : () => never
function f1(x: 0 | 1 | 2) {
>f1 : (x: 0 | 1 | 2) => void
>x : 0 | 1 | 2
switch (x) {
>x : 0 | 1 | 2
case 0:
>0 : 0
fail();
>fail() : never
>fail : () => never
case 1:
>1 : 1
noop();
>noop() : void
>noop : () => void
case 2:
>2 : 2
return;
}
}
// Repro from #34021
type Behavior = 'SLIDE' | 'SLIDE_OUT'
>Behavior : Behavior
type Direction = 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'
>Direction : Direction
interface Transition {
behavior: Behavior
>behavior : Behavior
direction: Direction
>direction : Direction
}
function f2(transition: Transition): any {
>f2 : (transition: Transition) => any
>transition : Transition
switch (transition.behavior) {
>transition.behavior : Behavior
>transition : Transition
>behavior : Behavior
case 'SLIDE':
>'SLIDE' : "SLIDE"
switch (transition.direction) {
>transition.direction : Direction
>transition : Transition
>direction : Direction
case 'LEFT':
>'LEFT' : "LEFT"
return []
>[] : undefined[]
case 'RIGHT':
>'RIGHT' : "RIGHT"
return []
>[] : undefined[]
case 'TOP':
>'TOP' : "TOP"
return []
>[] : undefined[]
case 'BOTTOM':
>'BOTTOM' : "BOTTOM"
return []
>[] : undefined[]
}
case 'SLIDE_OUT':
>'SLIDE_OUT' : "SLIDE_OUT"
switch (transition.direction) {
>transition.direction : Direction
>transition : Transition
>direction : Direction
case 'LEFT':
>'LEFT' : "LEFT"
return []
>[] : undefined[]
case 'RIGHT':
>'RIGHT' : "RIGHT"
return []
>[] : undefined[]
case 'TOP':
>'TOP' : "TOP"
return []
>[] : undefined[]
case 'BOTTOM':
>'BOTTOM' : "BOTTOM"
return []
>[] : undefined[]
}
}
}