From e12b2a7d276b82ab803e0c1d0e06a687bf557fb7 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 21 Apr 2016 16:06:05 -0700 Subject: [PATCH] Correct issue with exported variables in code flow analysis --- src/compiler/checker.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6bffe78bc75..ce17db0bd9a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7576,7 +7576,7 @@ namespace ts { // only need to evaluate the assigned type if the declared type is a union type. if ((node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) && reference.kind === SyntaxKind.Identifier && - getResolvedSymbol(reference) === getSymbolOfNode(node)) { + getExportSymbolOfValueSymbolIfExported(getResolvedSymbol(reference)) === getSymbolOfNode(node)) { return declaredType.flags & TypeFlags.Union ? getAssignmentReducedType(declaredType, getInitialType(node)) : declaredType; @@ -7857,7 +7857,7 @@ namespace ts { // symbol, use the location as the reference with respect to which we narrow. if (isExpression(location) && !isAssignmentTarget(location)) { checkExpression(location); - if (getNodeLinks(location).resolvedSymbol === symbol) { + if (getExportSymbolOfValueSymbolIfExported(getNodeLinks(location).resolvedSymbol) === symbol) { return getNarrowedTypeOfReference(type, location); } } @@ -9745,7 +9745,7 @@ namespace ts { } const propType = getTypeOfSymbol(prop); - return node.kind === SyntaxKind.PropertyAccessExpression && prop.flags & SymbolFlags.Property && !isAssignmentTarget(node) ? + return node.kind === SyntaxKind.PropertyAccessExpression && prop.flags & (SymbolFlags.Variable | SymbolFlags.Property) && !isAssignmentTarget(node) ? getNarrowedTypeOfReference(propType, node) : propType; }