From ade89a60327763ac09bc7083d1f9ffc9935682b1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 1 Aug 2016 06:41:05 -0700 Subject: [PATCH] Fix issue related to this and #8383 --- src/compiler/checker.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 691d7451895..155f8a2e676 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7789,6 +7789,10 @@ namespace ts { return false; } + function rootContainsMatchingReference(source: Node, target: Node) { + return target.kind === SyntaxKind.PropertyAccessExpression && containsMatchingReference(source, (target).expression); + } + function isOrContainsMatchingReference(source: Node, target: Node) { return isMatchingReference(source, target) || containsMatchingReference(source, target); } @@ -8294,6 +8298,9 @@ namespace ts { if (isMatchingPropertyAccess(expr)) { return narrowTypeByDiscriminant(type, expr, t => getTypeWithFacts(t, assumeTrue ? TypeFacts.Truthy : TypeFacts.Falsy)); } + if (rootContainsMatchingReference(reference, expr)) { + return declaredType; + } return type; } @@ -8326,6 +8333,9 @@ namespace ts { if (isMatchingPropertyAccess(right)) { return narrowTypeByDiscriminant(type, right, t => narrowTypeByEquality(t, operator, left, assumeTrue)); } + if (rootContainsMatchingReference(reference, left) || rootContainsMatchingReference(reference, right)) { + return declaredType; + } break; case SyntaxKind.InstanceOfKeyword: return narrowTypeByInstanceof(type, expr, assumeTrue);