diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a3b3451fe35..6bffe78bc75 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7197,19 +7197,7 @@ namespace ts { // EXPRESSION TYPE CHECKING - function createTransientIdentifier(symbol: Symbol, location: Node): Identifier { - const result = createNode(SyntaxKind.Identifier); - result.text = symbol.name; - result.resolvedSymbol = symbol; - result.parent = location; - result.id = -1; - return result; - } - function getResolvedSymbol(node: Identifier): Symbol { - if (node.id === -1) { - return (node).resolvedSymbol; - } const links = getNodeLinks(node); if (!links.resolvedSymbol) { links.resolvedSymbol = !nodeIsMissing(node) && resolveName(node, node.text, SymbolFlags.Value | SymbolFlags.ExportValue, Diagnostics.Cannot_find_name_0, node) || unknownSymbol; @@ -7867,7 +7855,7 @@ namespace ts { } // If location is an identifier or property access that references the given // symbol, use the location as the reference with respect to which we narrow. - if (isExpression(location)) { + if (isExpression(location) && !isAssignmentTarget(location)) { checkExpression(location); if (getNodeLinks(location).resolvedSymbol === symbol) { return getNarrowedTypeOfReference(type, location); @@ -7876,9 +7864,10 @@ namespace ts { } // The location isn't a reference to the given symbol, meaning we're being asked // a hypothetical question of what type the symbol would have if there was a reference - // to it at the given location. To answer that question we manufacture a transient - // identifier at the location and narrow with respect to that identifier. - return getNarrowedTypeOfReference(type, createTransientIdentifier(symbol, location)); + // to it at the given location. Since we have no control flow information for the + // hypotherical reference (control flow information is created and attached by the + // binder), we simply return the declared type of the symbol. + return type; } function skipParenthesizedNodes(expression: Expression): Expression { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b5e33d5d361..0a4de847c00 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -479,11 +479,6 @@ namespace ts { originalKeywordKind?: SyntaxKind; // Original syntaxKind which get set so that we can report an error later } - // Transient identifier node (marked by id === -1) - export interface TransientIdentifier extends Identifier { - resolvedSymbol: Symbol; - } - // @kind(SyntaxKind.QualifiedName) export interface QualifiedName extends Node { // Must have same layout as PropertyAccess