mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 06:41:59 -06:00
isValidPropertyAccessWithType: Simplify loop (#21725)
This commit is contained in:
parent
4cfb7a5105
commit
017f30eaf4
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user