diff --git a/tests/cases/compiler/useUnknownInCatchVariables01.ts b/tests/cases/compiler/useUnknownInCatchVariables01.ts new file mode 100644 index 00000000000..c9633c97e4f --- /dev/null +++ b/tests/cases/compiler/useUnknownInCatchVariables01.ts @@ -0,0 +1,23 @@ +// @useUnknownInCatchVariables: true + +try { + // ... +} +catch (e) { + // error! + void e.toUpperCase(); + void e++; + void e(); + + if (typeof e === "string") { + // works! + // We've narrowed 'e' down to the type 'string'. + console.log(e.toUpperCase()); + } + if (e instanceof Error) { + e.stack?.toUpperCase(); + } + if (typeof e === "number") { + e++; + } +} \ No newline at end of file