Skip to content

Commit

Permalink
isValidPropertyAccessWithType: Simplify loop (#21725)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored Feb 7, 2018
1 parent 4cfb7a5 commit 017f30e
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<UnionType>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) && (<UnionType>type).types.some(elementType => isValidPropertyAccessWithType(node, left, propertyName, elementType));
}

/**
Expand Down

0 comments on commit 017f30e

Please sign in to comment.