134 lines
6.3 KiB
Text
134 lines
6.3 KiB
Text
=== tests/cases/conformance/expressions/typeGuards/typeGuardsObjectMethods.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 : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
|
|
var strOrNum: string | number;
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
|
|
var var1: string | number;
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
|
|
var obj1 = {
|
|
>obj1 : Symbol(obj1, Decl(typeGuardsObjectMethods.ts, 8, 3))
|
|
|
|
// Inside method
|
|
method(param: string | number) {
|
|
>method : Symbol(method, Decl(typeGuardsObjectMethods.ts, 8, 12))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 10, 11))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 15, 11))
|
|
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 15, 11))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 15, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// parameters in function declaration
|
|
num = typeof param === "string" && param.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 10, 11))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 10, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
return strOrNum;
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
|
|
},
|
|
get prop() {
|
|
>prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 28, 11))
|
|
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 28, 11))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 28, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
return strOrNum;
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
|
|
},
|
|
set prop(param: string | number) {
|
|
>prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 33, 13))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsObjectMethods.ts, 7, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 38, 11))
|
|
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 38, 11))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsObjectMethods.ts, 38, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// parameters in function declaration
|
|
num = typeof param === "string" && param.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsObjectMethods.ts, 5, 3))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 33, 13))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsObjectMethods.ts, 33, 13))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
}
|
|
};
|
|
// return expression of the method
|
|
strOrNum = typeof obj1.method(strOrNum) === "string" && obj1.method(strOrNum);
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
>obj1.method : Symbol(method, Decl(typeGuardsObjectMethods.ts, 8, 12))
|
|
>obj1 : Symbol(obj1, Decl(typeGuardsObjectMethods.ts, 8, 3))
|
|
>method : Symbol(method, Decl(typeGuardsObjectMethods.ts, 8, 12))
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
>obj1.method : Symbol(method, Decl(typeGuardsObjectMethods.ts, 8, 12))
|
|
>obj1 : Symbol(obj1, Decl(typeGuardsObjectMethods.ts, 8, 3))
|
|
>method : Symbol(method, Decl(typeGuardsObjectMethods.ts, 8, 12))
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
|
|
// accessing getter property
|
|
strOrNum = typeof obj1.prop === "string" && obj1.prop;
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsObjectMethods.ts, 6, 3))
|
|
>obj1.prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
>obj1 : Symbol(obj1, Decl(typeGuardsObjectMethods.ts, 8, 3))
|
|
>prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
>obj1.prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
>obj1 : Symbol(obj1, Decl(typeGuardsObjectMethods.ts, 8, 3))
|
|
>prop : Symbol(prop, Decl(typeGuardsObjectMethods.ts, 22, 6), Decl(typeGuardsObjectMethods.ts, 32, 6))
|
|
|