Add this
narrowing test and update previous test
This commit is contained in:
parent
924f536ba6
commit
db3431e3af
17
tests/cases/compiler/anonymousClassExpression2.ts
Normal file
17
tests/cases/compiler/anonymousClassExpression2.ts
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue