=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNumber.ts === class C { private p: string }; >C : C, Symbol(C, Decl(typeGuardOfFormTypeOfNumber.ts, 0, 0)) >p : string, Symbol(p, Decl(typeGuardOfFormTypeOfNumber.ts, 0, 9)) var str: string; >str : string, Symbol(str, Decl(typeGuardOfFormTypeOfNumber.ts, 2, 3)) var bool: boolean; >bool : boolean, Symbol(bool, Decl(typeGuardOfFormTypeOfNumber.ts, 3, 3)) var num: number; >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) var strOrNum: string | number; >strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) var strOrBool: string | boolean; >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) var numOrBool: number | boolean >numOrBool : number | boolean, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) var strOrNumOrBool: string | number | boolean; >strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) var strOrC: string | C; >strOrC : string | C, Symbol(strOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 9, 3)) >C : C, Symbol(C, Decl(typeGuardOfFormTypeOfNumber.ts, 0, 0)) var numOrC: number | C; >numOrC : number | C, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) >C : C, Symbol(C, Decl(typeGuardOfFormTypeOfNumber.ts, 0, 0)) var boolOrC: boolean | C; >boolOrC : boolean | C, Symbol(boolOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 11, 3)) >C : C, Symbol(C, Decl(typeGuardOfFormTypeOfNumber.ts, 0, 0)) var c: C; >c : C, Symbol(c, Decl(typeGuardOfFormTypeOfNumber.ts, 12, 3)) >C : C, Symbol(C, Decl(typeGuardOfFormTypeOfNumber.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 === "number") { >typeof strOrNum === "number" : boolean >typeof strOrNum : string >strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) >"number" : string num = strOrNum; // number >num = strOrNum : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >strOrNum : number, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) } else { str === strOrNum; // string >str === strOrNum : boolean >str : string, Symbol(str, Decl(typeGuardOfFormTypeOfNumber.ts, 2, 3)) >strOrNum : string, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) } if (typeof numOrBool === "number") { >typeof numOrBool === "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) >"number" : string num = numOrBool; // number >num = numOrBool : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >numOrBool : number, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) } else { var x: number | boolean = numOrBool; // number | boolean >x : number | boolean, Symbol(x, Decl(typeGuardOfFormTypeOfNumber.ts, 28, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 61, 7)) >numOrBool : boolean, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) } if (typeof strOrNumOrBool === "number") { >typeof strOrNumOrBool === "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) >"number" : string num = strOrNumOrBool; // number >num = strOrNumOrBool : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >strOrNumOrBool : number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) } else { strOrBool = strOrNumOrBool; // string | boolean >strOrBool = strOrNumOrBool : string | boolean >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) >strOrNumOrBool : string | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) } if (typeof numOrC === "number") { >typeof numOrC === "number" : boolean >typeof numOrC : string >numOrC : number | C, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) >"number" : string num = numOrC; // number >num = numOrC : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >numOrC : number, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) } else { c = numOrC; // C >c = numOrC : C >c : C, Symbol(c, Decl(typeGuardOfFormTypeOfNumber.ts, 12, 3)) >numOrC : C, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) } // Narrowing occurs only if target type is a subtype of variable type if (typeof strOrBool === "number") { >typeof strOrBool === "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) >"number" : string var y1: string | boolean = strOrBool; // string | boolean >y1 : string | boolean, Symbol(y1, Decl(typeGuardOfFormTypeOfNumber.ts, 45, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 81, 7)) >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) } else { var y2: string | boolean = strOrBool; // string | boolean >y2 : string | boolean, Symbol(y2, Decl(typeGuardOfFormTypeOfNumber.ts, 48, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 84, 7)) >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 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 !== "number") { >typeof strOrNum !== "number" : boolean >typeof strOrNum : string >strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) >"number" : string str === strOrNum; // string >str === strOrNum : boolean >str : string, Symbol(str, Decl(typeGuardOfFormTypeOfNumber.ts, 2, 3)) >strOrNum : string, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) } else { num = strOrNum; // number >num = strOrNum : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >strOrNum : number, Symbol(strOrNum, Decl(typeGuardOfFormTypeOfNumber.ts, 5, 3)) } if (typeof numOrBool !== "number") { >typeof numOrBool !== "number" : boolean >typeof numOrBool : string >numOrBool : number | boolean, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) >"number" : string var x: number | boolean = numOrBool; // number | boolean >x : number | boolean, Symbol(x, Decl(typeGuardOfFormTypeOfNumber.ts, 28, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 61, 7)) >numOrBool : boolean, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) } else { num = numOrBool; // number >num = numOrBool : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >numOrBool : number, Symbol(numOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 7, 3)) } if (typeof strOrNumOrBool !== "number") { >typeof strOrNumOrBool !== "number" : boolean >typeof strOrNumOrBool : string >strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) >"number" : string strOrBool = strOrNumOrBool; // string | boolean >strOrBool = strOrNumOrBool : string | boolean >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) >strOrNumOrBool : string | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) } else { num = strOrNumOrBool; // number >num = strOrNumOrBool : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >strOrNumOrBool : number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 8, 3)) } if (typeof numOrC !== "number") { >typeof numOrC !== "number" : boolean >typeof numOrC : string >numOrC : number | C, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) >"number" : string c = numOrC; // C >c = numOrC : C >c : C, Symbol(c, Decl(typeGuardOfFormTypeOfNumber.ts, 12, 3)) >numOrC : C, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) } else { num = numOrC; // number >num = numOrC : number >num : number, Symbol(num, Decl(typeGuardOfFormTypeOfNumber.ts, 4, 3)) >numOrC : number, Symbol(numOrC, Decl(typeGuardOfFormTypeOfNumber.ts, 10, 3)) } // Narrowing occurs only if target type is a subtype of variable type if (typeof strOrBool !== "number") { >typeof strOrBool !== "number" : boolean >typeof strOrBool : string >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) >"number" : string var y1: string | boolean = strOrBool; // string | boolean >y1 : string | boolean, Symbol(y1, Decl(typeGuardOfFormTypeOfNumber.ts, 45, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 81, 7)) >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) } else { var y2: string | boolean = strOrBool; // string | boolean >y2 : string | boolean, Symbol(y2, Decl(typeGuardOfFormTypeOfNumber.ts, 48, 7), Decl(typeGuardOfFormTypeOfNumber.ts, 84, 7)) >strOrBool : string | boolean, Symbol(strOrBool, Decl(typeGuardOfFormTypeOfNumber.ts, 6, 3)) }