diff --git a/tests/cases/compiler/narrowingByDiscriminantInLoop.ts b/tests/cases/compiler/narrowingByDiscriminantInLoop.ts index d9519c57a62..f394018d2ce 100644 --- a/tests/cases/compiler/narrowingByDiscriminantInLoop.ts +++ b/tests/cases/compiler/narrowingByDiscriminantInLoop.ts @@ -1,3 +1,5 @@ +// @strictNullChecks: true + // Repro from #9977 type IDLMemberTypes = OperationMemberType | ConstantMemberType; @@ -12,7 +14,7 @@ interface InterfaceType { interface OperationMemberType { type: "operation"; - idlType: IDLTypeDescription | null; + idlType: IDLTypeDescription; } interface ConstantMemberType { @@ -47,4 +49,39 @@ function foo(memberType: IDLMemberTypes) { else if (memberType.type === "operation") { memberType.idlType.origin; // string } +} + +// Repro for issue similar to #8383 + +interface A { + kind: true; + prop: { a: string; }; +} + +interface B { + kind: false; + prop: { b: string; } +} + +function f1(x: A | B) { + while (true) { + x.prop; + if (x.kind === true) { + x.prop.a; + } + if (x.kind === false) { + x.prop.b; + } + } +} + +function f2(x: A | B) { + while (true) { + if (x.kind) { + x.prop.a; + } + if (!x.kind) { + x.prop.b; + } + } } \ No newline at end of file