Skip to content

Commit b3b4c34

Browse files
committed
Add additional tests
1 parent ade89a6 commit b3b4c34

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/cases/compiler/narrowingByDiscriminantInLoop.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @strictNullChecks: true
2+
13
// Repro from #9977
24

35
type IDLMemberTypes = OperationMemberType | ConstantMemberType;
@@ -12,7 +14,7 @@ interface InterfaceType {
1214

1315
interface OperationMemberType {
1416
type: "operation";
15-
idlType: IDLTypeDescription | null;
17+
idlType: IDLTypeDescription;
1618
}
1719

1820
interface ConstantMemberType {
@@ -47,4 +49,39 @@ function foo(memberType: IDLMemberTypes) {
4749
else if (memberType.type === "operation") {
4850
memberType.idlType.origin; // string
4951
}
52+
}
53+
54+
// Repro for issue similar to #8383
55+
56+
interface A {
57+
kind: true;
58+
prop: { a: string; };
59+
}
60+
61+
interface B {
62+
kind: false;
63+
prop: { b: string; }
64+
}
65+
66+
function f1(x: A | B) {
67+
while (true) {
68+
x.prop;
69+
if (x.kind === true) {
70+
x.prop.a;
71+
}
72+
if (x.kind === false) {
73+
x.prop.b;
74+
}
75+
}
76+
}
77+
78+
function f2(x: A | B) {
79+
while (true) {
80+
if (x.kind) {
81+
x.prop.a;
82+
}
83+
if (!x.kind) {
84+
x.prop.b;
85+
}
86+
}
5087
}

0 commit comments

Comments
 (0)