1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
=== tests/cases/compiler/nestedLoopTypeGuards.ts ===
// Repros from #10378
function f1() {
>f1 : () => void
var a: boolean | number | string;
>a : string | number | boolean
if (typeof a !== 'boolean') {
>typeof a !== 'boolean' : boolean
>typeof a : string
>a : string | number | boolean
>'boolean' : "boolean"
// a is narrowed to "number | string"
for (var i = 0; i < 1; i++) {
>i : number
>0 : 0
>i < 1 : boolean
>i : number
>1 : 1
>i++ : number
>i : number
for (var j = 0; j < 1; j++) {}
>j : number
>0 : 0
>j < 1 : boolean
>j : number
>1 : 1
>j++ : number
>j : number
if (typeof a === 'string') {
>typeof a === 'string' : boolean
>typeof a : string
>a : string | number
>'string' : "string"
// a is narrowed to "string'
for (var j = 0; j < 1; j++) {
>j : number
>0 : 0
>j < 1 : boolean
>j : number
>1 : 1
>j++ : number
>j : number
a.length; // Should not error here
>a.length : number
>a : string
>length : number
}
}
}
}
}
function f2() {
>f2 : () => void
var a: string | number;
>a : string | number
if (typeof a === 'string') {
>typeof a === 'string' : boolean
>typeof a : string
>a : string | number
>'string' : "string"
while (1) {
>1 : 1
while (1) {}
>1 : 1
if (typeof a === 'string') {
>typeof a === 'string' : boolean
>typeof a : string
>a : string
>'string' : "string"
while (1) {
>1 : 1
a.length; // Should not error here
>a.length : number
>a : string
>length : number
}
}
}
}
}
|