Add regression test

This commit is contained in:
Anders Hejlsberg 2018-10-08 10:00:15 -07:00
parent cb47351851
commit 077bd1afd1

View File

@ -66,4 +66,36 @@ function foo6(x: Item) {
if (x.foo !== undefined && x.qux) {
x.foo.length; // Error, intervening discriminant guard
}
}
}
// 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;
}
}
}
}