File tree Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Expand file tree Collapse file tree 3 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ tests/cases/compiler/narrowedConstInMethod.ts(6,28): error TS2531: Object is possibly 'null'.
2
+ tests/cases/compiler/narrowedConstInMethod.ts(15,28): error TS2531: Object is possibly 'null'.
3
+
4
+
5
+ ==== tests/cases/compiler/narrowedConstInMethod.ts (2 errors) ====
6
+
7
+ function f() {
8
+ const x: string | null = <any>{};
9
+ if (x !== null) {
10
+ return {
11
+ bar() { return x.length; } // Error: possibly null x
12
+ ~
13
+ !!! error TS2531: Object is possibly 'null'.
14
+ };
15
+ }
16
+ }
17
+
18
+ function f2() {
19
+ const x: string | null = <any>{};
20
+ if (x !== null) {
21
+ return class {
22
+ bar() { return x.length; } // Error: possibly null x
23
+ ~
24
+ !!! error TS2531: Object is possibly 'null'.
25
+ };
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ //// [narrowedConstInMethod.ts]
2
+
3
+ function f ( ) {
4
+ const x : string | null = < any > { } ;
5
+ if (x !== null) {
6
+ return {
7
+ bar ( ) { return x . length ; } // Error: possibly null x
8
+ } ;
9
+ }
10
+ }
11
+
12
+ function f2 ( ) {
13
+ const x : string | null = < any > { } ;
14
+ if (x !== null) {
15
+ return class {
16
+ bar ( ) { return x . length ; } // Error: possibly null x
17
+ } ;
18
+ }
19
+ }
20
+
21
+ //// [narrowedConstInMethod.js]
22
+ function f ( ) {
23
+ var x = { } ;
24
+ if ( x !== null ) {
25
+ return {
26
+ bar : function ( ) { return x . length ; } // Error: possibly null x
27
+ } ;
28
+ }
29
+ }
30
+ function f2 ( ) {
31
+ var x = { } ;
32
+ if ( x !== null ) {
33
+ return ( function ( ) {
34
+ function class_1 ( ) {
35
+ }
36
+ class_1 . prototype . bar = function ( ) { return x . length ; } ; // Error: possibly null x
37
+ return class_1 ;
38
+ } ( ) ) ;
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ // @strictNullChecks : true
2
+
3
+ function f ( ) {
4
+ const x : string | null = < any > { } ;
5
+ if ( x !== null ) {
6
+ return {
7
+ bar ( ) { return x . length ; } // Error: possibly null x
8
+ } ;
9
+ }
10
+ }
11
+
12
+ function f2 ( ) {
13
+ const x : string | null = < any > { } ;
14
+ if ( x !== null ) {
15
+ return class {
16
+ bar ( ) { return x . length ; } // Error: possibly null x
17
+ } ;
18
+ }
19
+ }
You can’t perform that action at this time.
0 commit comments