Add this narrowing test and update previous test

This commit is contained in:
Nathan Shively-Sanders 2017-04-05 11:06:14 -07:00
parent 924f536ba6
commit db3431e3af
2 changed files with 21 additions and 3 deletions

View file

@ -0,0 +1,17 @@
// Fixes #14860
// note: repros with `while (0);` too
// but it's less inscrutable and more obvious to put it *inside* the loop
while (0) {
class A {
methodA() {
this; //note: a this reference of some kind is required to trigger the bug
}
}
class B {
methodB() {
this.methodA; // error
this.methodB; // ok
}
}
}

View file

@ -1,10 +1,11 @@
// @strictNullChecks: true
// Fixes #10501, possibly null 'x'
function f() {
const x: string | null = <any>{};
if (x !== null) {
return {
bar() { return x.length; } // Error: possibly null x
bar() { return x.length; } // ok
};
}
}
@ -13,7 +14,7 @@ function f2() {
const x: string | null = <any>{};
if (x !== null) {
return class {
bar() { return x.length; } // Error: possibly null x
bar() { return x.length; } // ok
};
}
}
}