TypeScript/tests/baselines/reference/nestedLoopTypeGuards.types
Nathan Shively-Sanders 69e9bfef35 Add typeof test case and update baselines
Test that `typeof x === 'random' as string`:

1. Does not issue an error.
2. Does not narrow.
2017-01-31 10:28:32 -08:00

97 lines
2 KiB
Plaintext

=== 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" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>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" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>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" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>a : string | number
>'string' : "string"
while (1) {
>1 : 1
while (1) {}
>1 : 1
if (typeof a === 'string') {
>typeof a === 'string' : boolean
>typeof a : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function"
>a : string
>'string' : "string"
while (1) {
>1 : 1
a.length; // Should not error here
>a.length : number
>a : string
>length : number
}
}
}
}
}