From 47f6bb2e26a57e53346412c84b65f01029e6ddef Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 1 Aug 2016 09:49:27 -0700 Subject: [PATCH] Add test --- tests/cases/compiler/bestChoiceType.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/cases/compiler/bestChoiceType.ts diff --git a/tests/cases/compiler/bestChoiceType.ts b/tests/cases/compiler/bestChoiceType.ts new file mode 100644 index 00000000000..3f8ce4bc868 --- /dev/null +++ b/tests/cases/compiler/bestChoiceType.ts @@ -0,0 +1,19 @@ +// @strictNullChecks: true + +// Repro from #10041 + +(''.match(/ /) || []).map(s => s.toLowerCase()); + +// Similar cases + +function f1() { + let x = ''.match(/ /); + let y = x || []; + let z = y.map(s => s.toLowerCase()); +} + +function f2() { + let x = ''.match(/ /); + let y = x ? x : []; + let z = y.map(s => s.toLowerCase()); +}