108 lines
4.7 KiB
Plaintext
108 lines
4.7 KiB
Plaintext
=== 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))
|
|
}
|