|
| 1 | +=== tests/cases/compiler/narrowedConstInMethod.ts === |
| 2 | + |
| 3 | +function f() { |
| 4 | +>f : Symbol(f, Decl(narrowedConstInMethod.ts, 0, 0)) |
| 5 | + |
| 6 | + const x: string | null = <any>{}; |
| 7 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 2, 9)) |
| 8 | + |
| 9 | + if (x !== null) { |
| 10 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 2, 9)) |
| 11 | + |
| 12 | + return { |
| 13 | + bar() { return x.length; } // Error: possibly null x |
| 14 | +>bar : Symbol(bar, Decl(narrowedConstInMethod.ts, 4, 16)) |
| 15 | +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 16 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 2, 9)) |
| 17 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 18 | + |
| 19 | + }; |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +function f2() { |
| 24 | +>f2 : Symbol(f2, Decl(narrowedConstInMethod.ts, 8, 1)) |
| 25 | + |
| 26 | + const x: string | null = <any>{}; |
| 27 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 11, 9)) |
| 28 | + |
| 29 | + if (x !== null) { |
| 30 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 11, 9)) |
| 31 | + |
| 32 | + return class { |
| 33 | + bar() { return x.length; } // Error: possibly null x |
| 34 | +>bar : Symbol((Anonymous class).bar, Decl(narrowedConstInMethod.ts, 13, 22)) |
| 35 | +>x.length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 36 | +>x : Symbol(x, Decl(narrowedConstInMethod.ts, 11, 9)) |
| 37 | +>length : Symbol(String.length, Decl(lib.d.ts, --, --)) |
| 38 | + |
| 39 | + }; |
| 40 | + } |
| 41 | +} |
0 commit comments