TypeScript/tests/baselines/reference/typeGuardOfFormNotExpr.types

171 lines
8.1 KiB
Plaintext
Raw Normal View History

=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormNotExpr.ts ===
var str: string;
2015-04-13 23:01:57 +02:00
>str : string, Symbol(str, Decl(typeGuardOfFormNotExpr.ts, 0, 3))
var bool: boolean;
2015-04-13 23:01:57 +02:00
>bool : boolean, Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
var num: number;
2015-04-13 23:01:57 +02:00
>num : number, Symbol(num, Decl(typeGuardOfFormNotExpr.ts, 2, 3))
var strOrNum: string | number;
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
var strOrNumOrBool: string | number | boolean;
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
var numOrBool: number | boolean;
2015-04-13 23:01:57 +02:00
>numOrBool : number | boolean, 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")) {
>!(typeof strOrNum === "string") : boolean
>(typeof strOrNum === "string") : boolean
>typeof strOrNum === "string" : boolean
>typeof strOrNum : string
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
num === strOrNum; // number
>num === strOrNum : boolean
2015-04-13 23:01:57 +02:00
>num : number, Symbol(num, Decl(typeGuardOfFormNotExpr.ts, 2, 3))
>strOrNum : number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
}
else {
str = strOrNum; // string
>str = strOrNum : string
2015-04-13 23:01:57 +02:00
>str : string, Symbol(str, Decl(typeGuardOfFormNotExpr.ts, 0, 3))
>strOrNum : string, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
}
// !(typeguard1 || typeguard2)
if (!(typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number")) {
>!(typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number") : boolean
>(typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number") : boolean
>typeof strOrNumOrBool === "string" || typeof strOrNumOrBool === "number" : boolean
>typeof strOrNumOrBool === "string" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
>typeof strOrNumOrBool === "number" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"number" : string
bool = strOrNumOrBool; // boolean
>bool = strOrNumOrBool : boolean
2015-04-13 23:01:57 +02:00
>bool : boolean, Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
strOrNum = strOrNumOrBool; // string | number
>strOrNum = strOrNumOrBool : string | number
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : string | number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) || !(typeguard2)
if (!(typeof strOrNumOrBool !== "string") || !(typeof strOrNumOrBool !== "number")) {
>!(typeof strOrNumOrBool !== "string") || !(typeof strOrNumOrBool !== "number") : boolean
>!(typeof strOrNumOrBool !== "string") : boolean
>(typeof strOrNumOrBool !== "string") : boolean
>typeof strOrNumOrBool !== "string" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
>!(typeof strOrNumOrBool !== "number") : boolean
>(typeof strOrNumOrBool !== "number") : boolean
>typeof strOrNumOrBool !== "number" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"number" : string
strOrNum = strOrNumOrBool; // string | number
>strOrNum = strOrNumOrBool : string | number
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : string | number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
bool = strOrNumOrBool; // boolean
>bool = strOrNumOrBool : boolean
2015-04-13 23:01:57 +02:00
>bool : boolean, Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1 && typeguard2)
if (!(typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number")) {
>!(typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number") : boolean
>(typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number") : boolean
>typeof strOrNumOrBool !== "string" && typeof strOrNumOrBool !== "number" : boolean
>typeof strOrNumOrBool !== "string" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
>typeof strOrNumOrBool !== "number" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"number" : string
strOrNum = strOrNumOrBool; // string | number
>strOrNum = strOrNumOrBool : string | number
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : string | number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
bool = strOrNumOrBool; // boolean
>bool = strOrNumOrBool : boolean
2015-04-13 23:01:57 +02:00
>bool : boolean, Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) && !(typeguard2)
if (!(typeof strOrNumOrBool === "string") && !(typeof strOrNumOrBool === "number")) {
>!(typeof strOrNumOrBool === "string") && !(typeof strOrNumOrBool === "number") : boolean
>!(typeof strOrNumOrBool === "string") : boolean
>(typeof strOrNumOrBool === "string") : boolean
>typeof strOrNumOrBool === "string" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
>!(typeof strOrNumOrBool === "number") : boolean
>(typeof strOrNumOrBool === "number") : boolean
>typeof strOrNumOrBool === "number" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"number" : string
bool = strOrNumOrBool; // boolean
>bool = strOrNumOrBool : boolean
2015-04-13 23:01:57 +02:00
>bool : boolean, Symbol(bool, Decl(typeGuardOfFormNotExpr.ts, 1, 3))
>strOrNumOrBool : boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
strOrNum = strOrNumOrBool; // string | number
>strOrNum = strOrNumOrBool : string | number
2015-04-13 23:01:57 +02:00
>strOrNum : string | number, Symbol(strOrNum, Decl(typeGuardOfFormNotExpr.ts, 3, 3))
>strOrNumOrBool : string | number, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
// !(typeguard1) && simpleExpr
if (!(typeof strOrNumOrBool === "string") && numOrBool !== strOrNumOrBool) {
>!(typeof strOrNumOrBool === "string") && numOrBool !== strOrNumOrBool : boolean
>!(typeof strOrNumOrBool === "string") : boolean
>(typeof strOrNumOrBool === "string") : boolean
>typeof strOrNumOrBool === "string" : boolean
>typeof strOrNumOrBool : string
2015-04-13 23:01:57 +02:00
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
2015-04-13 21:36:11 +02:00
>"string" : string
>numOrBool !== strOrNumOrBool : boolean
2015-04-13 23:01:57 +02:00
>numOrBool : number | boolean, Symbol(numOrBool, Decl(typeGuardOfFormNotExpr.ts, 5, 3))
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
numOrBool = strOrNumOrBool; // number | boolean
>numOrBool = strOrNumOrBool : number | boolean
2015-04-13 23:01:57 +02:00
>numOrBool : number | boolean, Symbol(numOrBool, Decl(typeGuardOfFormNotExpr.ts, 5, 3))
>strOrNumOrBool : number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}
else {
var r1: string | number | boolean = strOrNumOrBool; // string | number | boolean
2015-04-13 23:01:57 +02:00
>r1 : string | number | boolean, Symbol(r1, Decl(typeGuardOfFormNotExpr.ts, 51, 7))
>strOrNumOrBool : string | number | boolean, Symbol(strOrNumOrBool, Decl(typeGuardOfFormNotExpr.ts, 4, 3))
}