55 lines
1.3 KiB
Plaintext
55 lines
1.3 KiB
Plaintext
|
=== tests/cases/conformance/expressions/typeGuards/typeGuardsInExternalModule.ts ===
|
||
|
// Note that type guards affect types of variables and parameters only and
|
||
|
// have no effect on members of objects such as properties.
|
||
|
|
||
|
// local variable in external module
|
||
|
var num: number;
|
||
|
>num : number
|
||
|
|
||
|
var var1: string | number;
|
||
|
>var1 : string | number
|
||
|
|
||
|
if (typeof var1 === "string") {
|
||
|
>typeof var1 === "string" : boolean
|
||
|
>typeof var1 : string
|
||
|
>var1 : string | number
|
||
|
|
||
|
num = var1.length; // string
|
||
|
>num = var1.length : number
|
||
|
>num : number
|
||
|
>var1.length : number
|
||
|
>var1 : string
|
||
|
>length : number
|
||
|
}
|
||
|
else {
|
||
|
num = var1; // number
|
||
|
>num = var1 : number
|
||
|
>num : number
|
||
|
>var1 : number
|
||
|
}
|
||
|
|
||
|
// exported variable in external module
|
||
|
var strOrNum: string | number;
|
||
|
>strOrNum : string | number
|
||
|
|
||
|
export var var2: string | number;
|
||
|
>var2 : string | number
|
||
|
|
||
|
if (typeof var2 === "string") {
|
||
|
>typeof var2 === "string" : boolean
|
||
|
>typeof var2 : string
|
||
|
>var2 : string | number
|
||
|
|
||
|
// export makes the var property and not variable
|
||
|
strOrNum = var2; // string | number
|
||
|
>strOrNum = var2 : string | number
|
||
|
>strOrNum : string | number
|
||
|
>var2 : string | number
|
||
|
}
|
||
|
else {
|
||
|
strOrNum = var2; // number | string
|
||
|
>strOrNum = var2 : string | number
|
||
|
>strOrNum : string | number
|
||
|
>var2 : string | number
|
||
|
}
|