mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add this narrowing test and update previous test
This commit is contained in:
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user