100 lines
1.7 KiB
Text
100 lines
1.7 KiB
Text
=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts ===
|
|
enum Color { R, G, B }
|
|
>Color : Color
|
|
>R : Color
|
|
>G : Color
|
|
>B : Color
|
|
|
|
function f1(x: Color | string) {
|
|
>f1 : (x: Color | string) => void
|
|
>x : Color | string
|
|
>Color : Color
|
|
|
|
if (typeof x === "number") {
|
|
>typeof x === "number" : boolean
|
|
>typeof x : string
|
|
>x : Color | string
|
|
>"number" : string
|
|
|
|
var y = x;
|
|
>y : Color
|
|
>x : Color
|
|
|
|
var y: Color;
|
|
>y : Color
|
|
>Color : Color
|
|
}
|
|
else {
|
|
var z = x;
|
|
>z : string
|
|
>x : string
|
|
|
|
var z: string;
|
|
>z : string
|
|
}
|
|
}
|
|
|
|
function f2(x: Color | string | string[]) {
|
|
>f2 : (x: Color | string | string[]) => void
|
|
>x : Color | string | string[]
|
|
>Color : Color
|
|
|
|
if (typeof x === "object") {
|
|
>typeof x === "object" : boolean
|
|
>typeof x : string
|
|
>x : Color | string | string[]
|
|
>"object" : string
|
|
|
|
var y = x;
|
|
>y : string[]
|
|
>x : string[]
|
|
|
|
var y: string[];
|
|
>y : string[]
|
|
}
|
|
if (typeof x === "number") {
|
|
>typeof x === "number" : boolean
|
|
>typeof x : string
|
|
>x : string[] | Color | string
|
|
>"number" : string
|
|
|
|
var z = x;
|
|
>z : Color
|
|
>x : Color
|
|
|
|
var z: Color;
|
|
>z : Color
|
|
>Color : Color
|
|
}
|
|
else {
|
|
var w = x;
|
|
>w : string[] | string
|
|
>x : string[] | string
|
|
|
|
var w: string | string[];
|
|
>w : string[] | string
|
|
}
|
|
if (typeof x === "string") {
|
|
>typeof x === "string" : boolean
|
|
>typeof x : string
|
|
>x : Color | string[] | string
|
|
>"string" : string
|
|
|
|
var a = x;
|
|
>a : string
|
|
>x : string
|
|
|
|
var a: string;
|
|
>a : string
|
|
}
|
|
else {
|
|
var b = x;
|
|
>b : Color | string[]
|
|
>x : Color | string[]
|
|
|
|
var b: Color | string[];
|
|
>b : Color | string[]
|
|
>Color : Color
|
|
}
|
|
}
|
|
|