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
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormNotExpr.ts ===
var str: string;
>str : Symbol(str, Decl(typeGuardOfFormNotExpr.ts, 0, 3))
var bool: boolean;
>bool : Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
var num: number;
>num : Symbol(num, Decl(typeGuardOfFormNotExpr.ts, 2, 3))
var strOrNum: string | number;
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
var strOrNumOrBool: string | number | boolean;
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
var numOrBool: number | boolean;
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormNotExpr.ts, 5, 3))
// A type guard of the form !expr
// - when true, narrows the type of x by expr when false, or
// - when false, narrows the type of x by expr when true.
// !typeguard1
if (!(typeof strOrNum === "string")) {
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
num === strOrNum; // number
>num : Symbol(num, Decl(typeGuardOfFormNotExpr.ts, 2, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
}
else {
str = strOrNum; // string
>str : Symbol(str, Decl(typeGuardOfFormNotExpr.ts, 0, 3))
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
}
// !(typeguard1 || typeguard2)
if (!(typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number")) {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
bool = strOrNumOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
strOrNum = strOrNumOrBool; // string | number
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) || !(typeguard2)
if (!(typeof strOrNumOrBool !== "string") || !(typeof strOrNumOrBool !== "number")) {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
strOrNum = strOrNumOrBool; // string | number
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
bool = strOrNumOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1 && typeguard2)
if (!(typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number")) {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
strOrNum = strOrNumOrBool; // string | number
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
bool = strOrNumOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) && !(typeguard2)
if (!(typeof strOrNumOrBool === "string") && !(typeof strOrNumOrBool === "number")) {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
bool = strOrNumOrBool; // boolean
>bool : Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
strOrNum = strOrNumOrBool; // string | number
>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) && simpleExpr
if (!(typeof strOrNumOrBool === "string") && numOrBool !== strOrNumOrBool) {
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormNotExpr.ts, 5, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
numOrBool = strOrNumOrBool; // number | boolean
>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormNotExpr.ts, 5, 3))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
var r1: string | number | boolean = strOrNumOrBool; // string | number | boolean
>r1 : Symbol(r1, Decl(typeGuardOfFormNotExpr.ts, 51, 7))
>strOrNumOrBool : Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
|