TypeScript/tests/cases/compiler/narrowByEquality.ts
2019-04-25 19:30:03 -07:00

60 lines
654 B
TypeScript

// @strict: true
declare let x: number | string | boolean
declare let n: number;
declare let s: string;
declare let b: boolean;
if (x == n) {
x;
}
if (x == s) {
x;
}
if (x == b) {
x;
}
if (x == 1) {
x;
}
if (x == "") {
x;
}
if (x == "foo") {
x;
}
if (x == true) {
x;
}
if (x == false) {
x;
}
declare let xAndObj: number | string | boolean | object
if (xAndObj == {}) {
xAndObj;
}
if (x == xAndObj) {
x;
xAndObj;
}
// Repro from #24991
function test(level: number | string):number {
if (level == +level) {
const q2: number = level; // error
return level;
}
return 0;
}