From 077bd1afd180ede4aa4990a69ae0bb8ebf2bb9aa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 8 Oct 2018 10:00:15 -0700 Subject: [PATCH] Add regression test --- .../compiler/discriminantPropertyCheck.ts | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tests/cases/compiler/discriminantPropertyCheck.ts b/tests/cases/compiler/discriminantPropertyCheck.ts index e493f6bf770..16fb847bdf0 100644 --- a/tests/cases/compiler/discriminantPropertyCheck.ts +++ b/tests/cases/compiler/discriminantPropertyCheck.ts @@ -66,4 +66,36 @@ function foo6(x: Item) { if (x.foo !== undefined && x.qux) { x.foo.length; // Error, intervening discriminant guard } -} \ No newline at end of file +} + +// Repro from #27493 + +enum Types { Str = 1, Num = 2 } + +type Instance = StrType | NumType; + +interface StrType { + type: Types.Str; + value: string; + length: number; +} + +interface NumType { + type: Types.Num; + value: number; +} + +function func2(inst: Instance) { + while (true) { + switch (inst.type) { + case Types.Str: { + inst.value.length; + break; + } + case Types.Num: { + inst.value.toExponential; + break; + } + } + } +}