From 67b4b9076d64e69d85441f7d6f723e86374e62f7 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 8 Oct 2020 16:43:00 -0700 Subject: [PATCH] Add test case for 'useUnknownInCatchVariables'. --- .../compiler/useUnknownInCatchVariables01.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/cases/compiler/useUnknownInCatchVariables01.ts 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