Skip to content

Commit 077bd1a

Browse files
committed
Add regression test
1 parent cb47351 commit 077bd1a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

tests/cases/compiler/discriminantPropertyCheck.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,36 @@ function foo6(x: Item) {
6666
if (x.foo !== undefined && x.qux) {
6767
x.foo.length; // Error, intervening discriminant guard
6868
}
69-
}
69+
}
70+
71+
// Repro from #27493
72+
73+
enum Types { Str = 1, Num = 2 }
74+
75+
type Instance = StrType | NumType;
76+
77+
interface StrType {
78+
type: Types.Str;
79+
value: string;
80+
length: number;
81+
}
82+
83+
interface NumType {
84+
type: Types.Num;
85+
value: number;
86+
}
87+
88+
function func2(inst: Instance) {
89+
while (true) {
90+
switch (inst.type) {
91+
case Types.Str: {
92+
inst.value.length;
93+
break;
94+
}
95+
case Types.Num: {
96+
inst.value.toExponential;
97+
break;
98+
}
99+
}
100+
}
101+
}

0 commit comments

Comments
 (0)