TypeScript/tests/baselines/reference/typeGuardOfFormTypeOfString.symbols
2015-04-15 16:44:20 -07:00

176 lines
7.1 KiB
Plaintext

=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfString.ts ===
class C { private p: string };
>C : Symbol(C, Decl(typeGuardOfFormTypeOfString.ts, 0, 0))
>p : Symbol(p, Decl(typeGuardOfFormTypeOfString.ts, 0, 9))
var str: string;
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
var bool: boolean;
>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfString.ts, 3, 3))
var num: number;
>num : Symbol(num, Decl(typeGuardOfFormTypeOfString.ts, 4, 3))
var strOrNum: string | number;
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
var strOrBool: string | boolean;
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
var numOrBool: number | boolean
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
var strOrNumOrBool: string | number | boolean;
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
var strOrC: string | C;
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
>C : Symbol(C, Decl(typeGuardOfFormTypeOfString.ts, 0, 0))
var numOrC: number | C;
>numOrC : Symbol(numOrC, Decl(typeGuardOfFormTypeOfString.ts, 10, 3))
>C : Symbol(C, Decl(typeGuardOfFormTypeOfString.ts, 0, 0))
var boolOrC: boolean | C;
>boolOrC : Symbol(boolOrC, Decl(typeGuardOfFormTypeOfString.ts, 11, 3))
>C : Symbol(C, Decl(typeGuardOfFormTypeOfString.ts, 0, 0))
var c: C;
>c : Symbol(c, Decl(typeGuardOfFormTypeOfString.ts, 12, 3))
>C : Symbol(C, Decl(typeGuardOfFormTypeOfString.ts, 0, 0))
// A type guard of the form typeof x === s,
// where s is a string literal with the value 'string', 'number', or 'boolean',
// - when true, narrows the type of x to the given primitive type, or
// - when false, removes the primitive type from the type of x.
if (typeof strOrNum === "string") {
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
str = strOrNum; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
}
else {
num === strOrNum; // number
>num : Symbol(num, Decl(typeGuardOfFormTypeOfString.ts, 4, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
}
if (typeof strOrBool === "string") {
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
str = strOrBool; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
}
else {
bool = strOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfString.ts, 3, 3))
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
}
if (typeof strOrNumOrBool === "string") {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
str = strOrNumOrBool; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
}
else {
numOrBool = strOrNumOrBool; // number | boolean
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
}
if (typeof strOrC === "string") {
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
str = strOrC; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
}
else {
c = strOrC; // C
>c : Symbol(c, Decl(typeGuardOfFormTypeOfString.ts, 12, 3))
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
}
// Narrowing occurs only if target type is a subtype of variable type
if (typeof numOrBool === "string") {
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
var x1: number | boolean = numOrBool; // number | boolean
>x1 : Symbol(x1, Decl(typeGuardOfFormTypeOfString.ts, 45, 7), Decl(typeGuardOfFormTypeOfString.ts, 81, 7))
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
}
else {
var x2: number | boolean = numOrBool; // number | boolean
>x2 : Symbol(x2, Decl(typeGuardOfFormTypeOfString.ts, 48, 7), Decl(typeGuardOfFormTypeOfString.ts, 84, 7))
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
}
// A type guard of the form typeof x !== s, where s is a string literal,
// - when true, narrows the type of x by typeof x === s when false, or
// - when false, narrows the type of x by typeof x === s when true.
if (typeof strOrNum !== "string") {
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
num === strOrNum; // number
>num : Symbol(num, Decl(typeGuardOfFormTypeOfString.ts, 4, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
}
else {
str = strOrNum; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfString.ts, 5, 3))
}
if (typeof strOrBool !== "string") {
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
bool = strOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfString.ts, 3, 3))
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
}
else {
str = strOrBool; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfString.ts, 6, 3))
}
if (typeof strOrNumOrBool !== "string") {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
numOrBool = strOrNumOrBool; // number | boolean
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
}
else {
str = strOrNumOrBool; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfString.ts, 8, 3))
}
if (typeof strOrC !== "string") {
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
c = strOrC; // C
>c : Symbol(c, Decl(typeGuardOfFormTypeOfString.ts, 12, 3))
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
}
else {
str = strOrC; // string
>str : Symbol(str, Decl(typeGuardOfFormTypeOfString.ts, 2, 3))
>strOrC : Symbol(strOrC, Decl(typeGuardOfFormTypeOfString.ts, 9, 3))
}
// Narrowing occurs only if target type is a subtype of variable type
if (typeof numOrBool !== "string") {
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
var x1: number | boolean = numOrBool; // number | boolean
>x1 : Symbol(x1, Decl(typeGuardOfFormTypeOfString.ts, 45, 7), Decl(typeGuardOfFormTypeOfString.ts, 81, 7))
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
}
else {
var x2: number | boolean = numOrBool; // number | boolean
>x2 : Symbol(x2, Decl(typeGuardOfFormTypeOfString.ts, 48, 7), Decl(typeGuardOfFormTypeOfString.ts, 84, 7))
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfString.ts, 7, 3))
}