Skip to content

Commit ade89a6

Browse files
committed
Fix issue related to this and #8383
1 parent d9b6723 commit ade89a6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/compiler/checker.ts

+10
Original file line numberDiff line numberDiff line change
@@ -7789,6 +7789,10 @@ namespace ts {
77897789
return false;
77907790
}
77917791

7792+
function rootContainsMatchingReference(source: Node, target: Node) {
7793+
return target.kind === SyntaxKind.PropertyAccessExpression && containsMatchingReference(source, (<PropertyAccessExpression>target).expression);
7794+
}
7795+
77927796
function isOrContainsMatchingReference(source: Node, target: Node) {
77937797
return isMatchingReference(source, target) || containsMatchingReference(source, target);
77947798
}
@@ -8294,6 +8298,9 @@ namespace ts {
82948298
if (isMatchingPropertyAccess(expr)) {
82958299
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy));
82968300
}
8301+
if (rootContainsMatchingReference(reference, expr)) {
8302+
return declaredType;
8303+
}
82978304
return type;
82988305
}
82998306

@@ -8326,6 +8333,9 @@ namespace ts {
83268333
if (isMatchingPropertyAccess(right)) {
83278334
return narrowTypeByDiscriminant(type, <PropertyAccessExpression>right, t => narrowTypeByEquality(t, operator, left, assumeTrue));
83288335
}
8336+
if (rootContainsMatchingReference(reference, left) || rootContainsMatchingReference(reference, right)) {
8337+
return declaredType;
8338+
}
83298339
break;
83308340
case SyntaxKind.InstanceOfKeyword:
83318341
return narrowTypeByInstanceof(type, expr, assumeTrue);

0 commit comments

Comments
 (0)