333 lines
9.6 KiB
Plaintext
333 lines
9.6 KiB
Plaintext
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInClassAccessors.ts ===
|
||
|
|
||
|
// Note that type guards affect types of variables and parameters only and
|
||
|
// have no effect on members of objects such as properties.
|
||
|
|
||
|
// variables in global
|
||
|
var num: number;
|
||
|
>num : number
|
||
|
|
||
|
var strOrNum: string | number;
|
||
|
>strOrNum : string | number
|
||
|
|
||
|
var var1: string | number;
|
||
|
>var1 : string | number
|
||
|
|
||
|
class ClassWithAccessors {
|
||
|
>ClassWithAccessors : ClassWithAccessors
|
||
|
|
||
|
// Inside public accessor getter
|
||
|
get p1() {
|
||
|
>p1 : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
|
||
|
return strOrNum;
|
||
|
>strOrNum : string | number
|
||
|
}
|
||
|
// Inside public accessor setter
|
||
|
set p1(param: string | number) {
|
||
|
>p1 : string | number
|
||
|
>param : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// parameter of function declaration
|
||
|
num = typeof param === "string" && param.length; // string
|
||
|
>num = typeof param === "string" && param.length : number
|
||
|
>num : number
|
||
|
>typeof param === "string" && param.length : number
|
||
|
>typeof param === "string" : boolean
|
||
|
>typeof param : string
|
||
|
>param : string | number
|
||
|
>param.length : number
|
||
|
>param : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
}
|
||
|
// Inside private accessor getter
|
||
|
private get pp1() {
|
||
|
>pp1 : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
|
||
|
return strOrNum;
|
||
|
>strOrNum : string | number
|
||
|
}
|
||
|
// Inside private accessor setter
|
||
|
private set pp1(param: string | number) {
|
||
|
>pp1 : string | number
|
||
|
>param : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// parameter of function declaration
|
||
|
num = typeof param === "string" && param.length; // string
|
||
|
>num = typeof param === "string" && param.length : number
|
||
|
>num : number
|
||
|
>typeof param === "string" && param.length : number
|
||
|
>typeof param === "string" : boolean
|
||
|
>typeof param : string
|
||
|
>param : string | number
|
||
|
>param.length : number
|
||
|
>param : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
}
|
||
|
// Inside static accessor getter
|
||
|
static get s1() {
|
||
|
>s1 : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
|
||
|
return strOrNum;
|
||
|
>strOrNum : string | number
|
||
|
}
|
||
|
// Inside static accessor setter
|
||
|
static set s1(param: string | number) {
|
||
|
>s1 : string | number
|
||
|
>param : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// parameter of function declaration
|
||
|
num = typeof param === "string" && param.length; // string
|
||
|
>num = typeof param === "string" && param.length : number
|
||
|
>num : number
|
||
|
>typeof param === "string" && param.length : number
|
||
|
>typeof param === "string" : boolean
|
||
|
>typeof param : string
|
||
|
>param : string | number
|
||
|
>param.length : number
|
||
|
>param : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
}
|
||
|
// Inside private static accessor getter
|
||
|
private static get ss1() {
|
||
|
>ss1 : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
|
||
|
return strOrNum;
|
||
|
>strOrNum : string | number
|
||
|
}
|
||
|
// Inside private static accessor setter
|
||
|
private static set ss1(param: string | number) {
|
||
|
>ss1 : string | number
|
||
|
>param : string | number
|
||
|
|
||
|
// global vars in function declaration
|
||
|
num = typeof var1 === "string" && var1.length; // string
|
||
|
>num = typeof var1 === "string" && var1.length : number
|
||
|
>num : number
|
||
|
>typeof var1 === "string" && var1.length : number
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
|
||
|
// parameter of function declaration
|
||
|
num = typeof param === "string" && param.length; // string
|
||
|
>num = typeof param === "string" && param.length : number
|
||
|
>num : number
|
||
|
>typeof param === "string" && param.length : number
|
||
|
>typeof param === "string" : boolean
|
||
|
>typeof param : string
|
||
|
>param : string | number
|
||
|
>param.length : number
|
||
|
>param : string
|
||
|
>length : number
|
||
|
|
||
|
// variables in function declaration
|
||
|
var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
num = typeof var2 === "string" && var2.length; // string
|
||
|
>num = typeof var2 === "string" && var2.length : number
|
||
|
>num : number
|
||
|
>typeof var2 === "string" && var2.length : number
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
>var2.length : number
|
||
|
>var2 : string
|
||
|
>length : number
|
||
|
}
|
||
|
}
|
||
|
|