Skip to content

Commit 39c4e8a

Browse files
committed
Remove unnecessary restrictions in property access narrowing
1 parent 3aaa4ea commit 39c4e8a

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

src/compiler/checker.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9991,24 +9991,14 @@ namespace ts {
99919991
}
99929992

99939993
const propType = getTypeOfSymbol(prop);
9994+
// Only compute control flow type if this is a property access expression that isn't an
9995+
// assignment target, and the referenced property was declared as a variable, property,
9996+
// accessor, or optional method.
99949997
if (node.kind !== SyntaxKind.PropertyAccessExpression || isAssignmentTarget(node) ||
9995-
!(propType.flags & TypeFlags.Union) && !(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor))) {
9998+
!(prop.flags & (SymbolFlags.Variable | SymbolFlags.Property | SymbolFlags.Accessor)) &&
9999+
!(prop.flags & SymbolFlags.Method && propType.flags & TypeFlags.Union)) {
999610000
return propType;
999710001
}
9998-
const leftmostNode = getLeftmostIdentifierOrThis(node);
9999-
if (!leftmostNode) {
10000-
return propType;
10001-
}
10002-
if (leftmostNode.kind === SyntaxKind.Identifier) {
10003-
const leftmostSymbol = getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(<Identifier>leftmostNode));
10004-
if (!leftmostSymbol) {
10005-
return propType;
10006-
}
10007-
const declaration = leftmostSymbol.valueDeclaration;
10008-
if (!declaration || declaration.kind !== SyntaxKind.VariableDeclaration && declaration.kind !== SyntaxKind.Parameter && declaration.kind !== SyntaxKind.BindingElement) {
10009-
return propType;
10010-
}
10011-
}
1001210002
return getFlowTypeOfReference(node, propType, /*assumeInitialized*/ true, /*includeOuterFunctions*/ false);
1001310003
}
1001410004

0 commit comments

Comments
 (0)