1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts ===
class C { private p: string };
>C : C
>p : string
var strOrNum: string | number;
>strOrNum : string | number
var strOrBool: string | boolean;
>strOrBool : string | boolean
var numOrBool: number | boolean
>numOrBool : number | boolean
var strOrC: string | C;
>strOrC : string | C
// typeof x == s has not effect on typeguard
if (typeof strOrNum == "string") {
>typeof strOrNum == "string" : boolean
>typeof strOrNum : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrNum : string | number
>"string" : "string"
var r1 = strOrNum; // string | number
>r1 : string
>strOrNum : string
}
else {
var r1 = strOrNum; // string | number
>r1 : string
>strOrNum : number
}
if (typeof strOrBool == "boolean") {
>typeof strOrBool == "boolean" : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>"boolean" : "boolean"
var r2 = strOrBool; // string | boolean
>r2 : boolean
>strOrBool : boolean
}
else {
var r2 = strOrBool; // string | boolean
>r2 : boolean
>strOrBool : string
}
if (typeof numOrBool == "number") {
>typeof numOrBool == "number" : boolean
>typeof numOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>numOrBool : number | boolean
>"number" : "number"
var r3 = numOrBool; // number | boolean
>r3 : number
>numOrBool : number
}
else {
var r3 = numOrBool; // number | boolean
>r3 : number
>numOrBool : boolean
}
if (typeof strOrC == "Object") {
>typeof strOrC == "Object" : boolean
>typeof strOrC : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrC : string | C
>"Object" : "Object"
var r4 = strOrC; // string | C
>r4 : C
>strOrC : C
}
else {
var r4 = strOrC; // string | C
>r4 : C
>strOrC : string
}
|