2015-01-25 02:23:22 +01:00
|
|
|
=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts ===
|
|
|
|
enum Color { R, G, B }
|
2015-04-13 23:01:57 +02:00
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
|
|
|
>R : Color, Symbol(Color.R, Decl(TypeGuardWithEnumUnion.ts, 0, 12))
|
|
|
|
>G : Color, Symbol(Color.G, Decl(TypeGuardWithEnumUnion.ts, 0, 15))
|
|
|
|
>B : Color, Symbol(Color.B, Decl(TypeGuardWithEnumUnion.ts, 0, 18))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
function f1(x: Color | string) {
|
2015-04-13 23:01:57 +02:00
|
|
|
>f1 : (x: string | Color) => void, Symbol(f1, Decl(TypeGuardWithEnumUnion.ts, 0, 22))
|
|
|
|
>x : string | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 2, 12))
|
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
if (typeof x === "number") {
|
|
|
|
>typeof x === "number" : boolean
|
|
|
|
>typeof x : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>x : string | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 2, 12))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"number" : string
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var y = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>y : Color, Symbol(y, Decl(TypeGuardWithEnumUnion.ts, 4, 11), Decl(TypeGuardWithEnumUnion.ts, 5, 11))
|
|
|
|
>x : Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 2, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var y: Color;
|
2015-04-13 23:01:57 +02:00
|
|
|
>y : Color, Symbol(y, Decl(TypeGuardWithEnumUnion.ts, 4, 11), Decl(TypeGuardWithEnumUnion.ts, 5, 11))
|
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var z = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>z : string, Symbol(z, Decl(TypeGuardWithEnumUnion.ts, 8, 11), Decl(TypeGuardWithEnumUnion.ts, 9, 11))
|
|
|
|
>x : string, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 2, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var z: string;
|
2015-04-13 23:01:57 +02:00
|
|
|
>z : string, Symbol(z, Decl(TypeGuardWithEnumUnion.ts, 8, 11), Decl(TypeGuardWithEnumUnion.ts, 9, 11))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function f2(x: Color | string | string[]) {
|
2015-04-13 23:01:57 +02:00
|
|
|
>f2 : (x: string | string[] | Color) => void, Symbol(f2, Decl(TypeGuardWithEnumUnion.ts, 11, 1))
|
|
|
|
>x : string | string[] | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
if (typeof x === "object") {
|
|
|
|
>typeof x === "object" : boolean
|
|
|
|
>typeof x : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>x : string | string[] | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"object" : string
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var y = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>y : string[], Symbol(y, Decl(TypeGuardWithEnumUnion.ts, 15, 11), Decl(TypeGuardWithEnumUnion.ts, 16, 11))
|
|
|
|
>x : string[], Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var y: string[];
|
2015-04-13 23:01:57 +02:00
|
|
|
>y : string[], Symbol(y, Decl(TypeGuardWithEnumUnion.ts, 15, 11), Decl(TypeGuardWithEnumUnion.ts, 16, 11))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
if (typeof x === "number") {
|
|
|
|
>typeof x === "number" : boolean
|
|
|
|
>typeof x : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>x : string | string[] | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"number" : string
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var z = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>z : Color, Symbol(z, Decl(TypeGuardWithEnumUnion.ts, 19, 11), Decl(TypeGuardWithEnumUnion.ts, 20, 11))
|
|
|
|
>x : Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var z: Color;
|
2015-04-13 23:01:57 +02:00
|
|
|
>z : Color, Symbol(z, Decl(TypeGuardWithEnumUnion.ts, 19, 11), Decl(TypeGuardWithEnumUnion.ts, 20, 11))
|
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var w = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>w : string | string[], Symbol(w, Decl(TypeGuardWithEnumUnion.ts, 23, 11), Decl(TypeGuardWithEnumUnion.ts, 24, 11))
|
|
|
|
>x : string | string[], Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var w: string | string[];
|
2015-04-13 23:01:57 +02:00
|
|
|
>w : string | string[], Symbol(w, Decl(TypeGuardWithEnumUnion.ts, 23, 11), Decl(TypeGuardWithEnumUnion.ts, 24, 11))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
if (typeof x === "string") {
|
|
|
|
>typeof x === "string" : boolean
|
|
|
|
>typeof x : string
|
2015-04-13 23:01:57 +02:00
|
|
|
>x : string | string[] | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-04-13 21:36:11 +02:00
|
|
|
>"string" : string
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var a = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(TypeGuardWithEnumUnion.ts, 27, 11), Decl(TypeGuardWithEnumUnion.ts, 28, 11))
|
|
|
|
>x : string, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var a: string;
|
2015-04-13 23:01:57 +02:00
|
|
|
>a : string, Symbol(a, Decl(TypeGuardWithEnumUnion.ts, 27, 11), Decl(TypeGuardWithEnumUnion.ts, 28, 11))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var b = x;
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : string[] | Color, Symbol(b, Decl(TypeGuardWithEnumUnion.ts, 31, 11), Decl(TypeGuardWithEnumUnion.ts, 32, 11))
|
|
|
|
>x : string[] | Color, Symbol(x, Decl(TypeGuardWithEnumUnion.ts, 13, 12))
|
2015-01-25 02:23:22 +01:00
|
|
|
|
|
|
|
var b: Color | string[];
|
2015-04-13 23:01:57 +02:00
|
|
|
>b : string[] | Color, Symbol(b, Decl(TypeGuardWithEnumUnion.ts, 31, 11), Decl(TypeGuardWithEnumUnion.ts, 32, 11))
|
|
|
|
>Color : Color, Symbol(Color, Decl(TypeGuardWithEnumUnion.ts, 0, 0))
|
2015-01-25 02:23:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|