26 lines
919 B
Text
26 lines
919 B
Text
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInGlobal.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(typeGuardsInGlobal.ts, 4, 3))
|
|
|
|
var var1: string | number;
|
|
>var1 : Symbol(var1, Decl(typeGuardsInGlobal.ts, 5, 3))
|
|
|
|
if (typeof var1 === "string") {
|
|
>var1 : Symbol(var1, Decl(typeGuardsInGlobal.ts, 5, 3))
|
|
|
|
num = var1.length; // string
|
|
>num : Symbol(num, Decl(typeGuardsInGlobal.ts, 4, 3))
|
|
>var1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInGlobal.ts, 5, 3))
|
|
>length : Symbol(String.length, Decl(lib.d.ts, 414, 19))
|
|
}
|
|
else {
|
|
num = var1; // number
|
|
>num : Symbol(num, Decl(typeGuardsInGlobal.ts, 4, 3))
|
|
>var1 : Symbol(var1, Decl(typeGuardsInGlobal.ts, 5, 3))
|
|
}
|
|
|