From 017f30eaf4e67ac4e9887bb66f1b9a76b902b5f9 Mon Sep 17 00:00:00 2001 From: Andy Date: Wed, 7 Feb 2018 10:23:36 -0800 Subject: [PATCH] isValidPropertyAccessWithType: Simplify loop (#21725) --- src/compiler/checker.ts | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c7cdb922cc6..3b1771d2096 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16188,24 +16188,13 @@ namespace ts { propertyName: __String, type: Type): boolean { - if (type !== unknownType && !isTypeAny(type)) { - const prop = getPropertyOfType(type, propertyName); - if (prop) { - return checkPropertyAccessibility(node, left, type, prop); - } - - // In js files properties of unions are allowed in completion - if (isInJavaScriptFile(left) && (type.flags & TypeFlags.Union)) { - for (const elementType of (type).types) { - if (isValidPropertyAccessWithType(node, left, propertyName, elementType)) { - return true; - } - } - } - - return false; + if (type === unknownType || isTypeAny(type)) { + return true; } - return true; + const prop = getPropertyOfType(type, propertyName); + return prop ? checkPropertyAccessibility(node, left, type, prop) + // In js files properties of unions are allowed in completion + : isInJavaScriptFile(node) && (type.flags & TypeFlags.Union) && (type).types.some(elementType => isValidPropertyAccessWithType(node, left, propertyName, elementType)); } /**