Skip to content

Commit db3431e

Browse files
committed
Add this narrowing test and update previous test
1 parent 924f536 commit db3431e

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Fixes #14860
2+
// note: repros with `while (0);` too
3+
// but it's less inscrutable and more obvious to put it *inside* the loop
4+
while (0) {
5+
class A {
6+
methodA() {
7+
this; //note: a this reference of some kind is required to trigger the bug
8+
}
9+
}
10+
11+
class B {
12+
methodB() {
13+
this.methodA; // error
14+
this.methodB; // ok
15+
}
16+
}
17+
}
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// @strictNullChecks: true
22

3+
// Fixes #10501, possibly null 'x'
34
function f() {
45
const x: string | null = <any>{};
56
if (x !== null) {
67
return {
7-
bar() { return x.length; } // Error: possibly null x
8+
bar() { return x.length; } // ok
89
};
910
}
1011
}
@@ -13,7 +14,7 @@ function f2() {
1314
const x: string | null = <any>{};
1415
if (x !== null) {
1516
return class {
16-
bar() { return x.length; } // Error: possibly null x
17+
bar() { return x.length; } // ok
1718
};
1819
}
19-
}
20+
}

0 commit comments

Comments
 (0)