|
| 1 | +=== tests/cases/compiler/useUnknownInCatchVariables01.ts === |
| 2 | +try { |
| 3 | + // ... |
| 4 | +} |
| 5 | +catch (e) { |
| 6 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 7 | + |
| 8 | + // error! |
| 9 | + void e.toUpperCase(); |
| 10 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 11 | + |
| 12 | + void e++; |
| 13 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 14 | + |
| 15 | + void e(); |
| 16 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 17 | + |
| 18 | + if (typeof e === "string") { |
| 19 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 20 | + |
| 21 | + // works! |
| 22 | + // We've narrowed 'e' down to the type 'string'. |
| 23 | + console.log(e.toUpperCase()); |
| 24 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 25 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 26 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 27 | +>e.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 28 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 29 | +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 30 | + } |
| 31 | + if (e instanceof Error) { |
| 32 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 33 | +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) |
| 34 | + |
| 35 | + e.stack?.toUpperCase(); |
| 36 | +>e.stack?.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 37 | +>e.stack : Symbol(Error.stack, Decl(lib.es5.d.ts, --, --)) |
| 38 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 39 | +>stack : Symbol(Error.stack, Decl(lib.es5.d.ts, --, --)) |
| 40 | +>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --)) |
| 41 | + } |
| 42 | + if (typeof e === "number") { |
| 43 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 44 | + |
| 45 | + e++; |
| 46 | +>e : Symbol(e, Decl(useUnknownInCatchVariables01.ts, 3, 7)) |
| 47 | + } |
| 48 | +} |
0 commit comments