236 lines
10 KiB
Text
236 lines
10 KiB
Text
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInFunction.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(typeGuardsInFunction.ts, 4, 3))
|
|
|
|
var var1: string | number;
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
|
|
// Inside function declaration
|
|
function f(param: string | number) {
|
|
>f : Symbol(f, Decl(typeGuardsInFunction.ts, 5, 26))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 7, 11))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 12, 7))
|
|
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 12, 7))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 12, 7))
|
|
>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(typeGuardsInFunction.ts, 4, 3))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 7, 11))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 7, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
}
|
|
// local function declaration
|
|
function f1(param: string | number) {
|
|
>f1 : Symbol(f1, Decl(typeGuardsInFunction.ts, 17, 1))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 19, 12))
|
|
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 20, 7))
|
|
|
|
function f2(param1: string | number) {
|
|
>f2 : Symbol(f2, Decl(typeGuardsInFunction.ts, 20, 30))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 21, 16))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables from outer function declaration
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 20, 7))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 20, 7))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// parameters in outer declaration
|
|
num = typeof param === "string" && param.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 19, 12))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 19, 12))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// local
|
|
var var3: string | number;
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 32, 11))
|
|
|
|
num = typeof var3 === "string" && var3.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 32, 11))
|
|
>var3.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 32, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
num = typeof param1 === "string" && param1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 21, 16))
|
|
>param1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 21, 16))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
}
|
|
}
|
|
// Function expression
|
|
function f2(param: string | number) {
|
|
>f2 : Symbol(f2, Decl(typeGuardsInFunction.ts, 36, 1))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 38, 12))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 40, 7))
|
|
|
|
// variables in function expressions
|
|
var r = function (param1: string | number) {
|
|
>r : Symbol(r, Decl(typeGuardsInFunction.ts, 42, 7))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 42, 22))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables from outer function declaration
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 40, 7))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 40, 7))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// parameters in outer declaration
|
|
num = typeof param === "string" && param.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 38, 12))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 38, 12))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// local
|
|
var var3: string | number;
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 53, 11))
|
|
|
|
num = typeof var3 === "string" && var3.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 53, 11))
|
|
>var3.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 53, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
num = typeof param1 === "string" && param1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 42, 22))
|
|
>param1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 42, 22))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
} (param);
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 38, 12))
|
|
}
|
|
// Arrow expression
|
|
function f3(param: string | number) {
|
|
>f3 : Symbol(f3, Decl(typeGuardsInFunction.ts, 57, 1))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 59, 12))
|
|
|
|
// variables in function declaration
|
|
var var2: string | number;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 61, 7))
|
|
|
|
// variables in function expressions
|
|
var r = ((param1: string | number) => {
|
|
>r : Symbol(r, Decl(typeGuardsInFunction.ts, 63, 7))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 63, 14))
|
|
|
|
// global vars in function declaration
|
|
num = typeof var1 === "string" && var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInFunction.ts, 5, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// variables from outer function declaration
|
|
num = typeof var2 === "string" && var2.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 61, 7))
|
|
>var2.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 61, 7))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// parameters in outer declaration
|
|
num = typeof param === "string" && param.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 59, 12))
|
|
>param.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 59, 12))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
// local
|
|
var var3: string | number;
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 74, 11))
|
|
|
|
num = typeof var3 === "string" && var3.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 74, 11))
|
|
>var3.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var3 : Symbol(var3, Decl(typeGuardsInFunction.ts, 74, 11))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
num = typeof param1 === "string" && param1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInFunction.ts, 4, 3))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 63, 14))
|
|
>param1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>param1 : Symbol(param1, Decl(typeGuardsInFunction.ts, 63, 14))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
|
|
})(param);
|
|
>param : Symbol(param, Decl(typeGuardsInFunction.ts, 59, 12))
|
|
}
|
|
// Return type of function
|
|
// Inside function declaration
|
|
var strOrNum: string | number;
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsInFunction.ts, 81, 3))
|
|
|
|
function f4() {
|
|
>f4 : Symbol(f4, Decl(typeGuardsInFunction.ts, 81, 30))
|
|
|
|
var var2: string | number = strOrNum;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 83, 7))
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsInFunction.ts, 81, 3))
|
|
|
|
return var2;
|
|
>var2 : Symbol(var2, Decl(typeGuardsInFunction.ts, 83, 7))
|
|
}
|
|
strOrNum = typeof f4() === "string" && f4(); // string | number
|
|
>strOrNum : Symbol(strOrNum, Decl(typeGuardsInFunction.ts, 81, 3))
|
|
>f4 : Symbol(f4, Decl(typeGuardsInFunction.ts, 81, 30))
|
|
>f4 : Symbol(f4, Decl(typeGuardsInFunction.ts, 81, 30))
|
|
|