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; + } + } + } +}