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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardNesting.ts ===
let strOrBool: string|boolean;
>strOrBool : string | boolean
if ((typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'string') {
>(typeof strOrBool === 'boolean' && !strOrBool) || typeof strOrBool === 'string' : boolean
>(typeof strOrBool === 'boolean' && !strOrBool) : boolean
>typeof strOrBool === 'boolean' && !strOrBool : boolean
>typeof strOrBool === 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'boolean' : "boolean"
>!strOrBool : boolean
>strOrBool : boolean
>typeof strOrBool === 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | true
>'string' : "string"
let label: string = (typeof strOrBool === 'string') ? strOrBool : "string";
>label : string
>(typeof strOrBool === 'string') ? strOrBool : "string" : string
>(typeof strOrBool === 'string') : boolean
>typeof strOrBool === 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'string' : "string"
>strOrBool : string
>"string" : "string"
let bool: boolean = (typeof strOrBool === 'boolean') ? strOrBool : false;
>bool : boolean
>(typeof strOrBool === 'boolean') ? strOrBool : false : boolean
>(typeof strOrBool === 'boolean') : boolean
>typeof strOrBool === 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'boolean' : "boolean"
>strOrBool : boolean
>false : false
let label2: string = (typeof strOrBool !== 'boolean') ? strOrBool : "string";
>label2 : string
>(typeof strOrBool !== 'boolean') ? strOrBool : "string" : string
>(typeof strOrBool !== 'boolean') : boolean
>typeof strOrBool !== 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'boolean' : "boolean"
>strOrBool : string
>"string" : "string"
let bool2: boolean = (typeof strOrBool !== 'string') ? strOrBool : false;
>bool2 : boolean
>(typeof strOrBool !== 'string') ? strOrBool : false : boolean
>(typeof strOrBool !== 'string') : boolean
>typeof strOrBool !== 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'string' : "string"
>strOrBool : boolean
>false : false
}
if ((typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boolean') {
>(typeof strOrBool !== 'string' && !strOrBool) || typeof strOrBool !== 'boolean' : boolean
>(typeof strOrBool !== 'string' && !strOrBool) : boolean
>typeof strOrBool !== 'string' && !strOrBool : boolean
>typeof strOrBool !== 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'string' : "string"
>!strOrBool : boolean
>strOrBool : boolean
>typeof strOrBool !== 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | true
>'boolean' : "boolean"
let label: string = (typeof strOrBool === 'string') ? strOrBool : "string";
>label : string
>(typeof strOrBool === 'string') ? strOrBool : "string" : string
>(typeof strOrBool === 'string') : boolean
>typeof strOrBool === 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'string' : "string"
>strOrBool : string
>"string" : "string"
let bool: boolean = (typeof strOrBool === 'boolean') ? strOrBool : false;
>bool : boolean
>(typeof strOrBool === 'boolean') ? strOrBool : false : boolean
>(typeof strOrBool === 'boolean') : boolean
>typeof strOrBool === 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'boolean' : "boolean"
>strOrBool : boolean
>false : false
let label2: string = (typeof strOrBool !== 'boolean') ? strOrBool : "string";
>label2 : string
>(typeof strOrBool !== 'boolean') ? strOrBool : "string" : string
>(typeof strOrBool !== 'boolean') : boolean
>typeof strOrBool !== 'boolean' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'boolean' : "boolean"
>strOrBool : string
>"string" : "string"
let bool2: boolean = (typeof strOrBool !== 'string') ? strOrBool : false;
>bool2 : boolean
>(typeof strOrBool !== 'string') ? strOrBool : false : boolean
>(typeof strOrBool !== 'string') : boolean
>typeof strOrBool !== 'string' : boolean
>typeof strOrBool : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>strOrBool : string | boolean
>'string' : "string"
>strOrBool : boolean
>false : false
}
|