diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d6db67d3fa..8568f8cf4a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3166,17 +3166,17 @@ namespace ts { } let type: Type = undefined; - // Handle module.exports = expr or this.p = expr - if (declaration.kind === SyntaxKind.BinaryExpression) { - type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right))); - } - else if (declaration.kind === SyntaxKind.PropertyAccessExpression) { - // Declarations only exist for property access expressions for certain - // special assignment kinds - if (declaration.parent.kind === SyntaxKind.BinaryExpression) { - // Handle exports.p = expr or className.prototype.method = expr - type = checkExpressionCached((declaration.parent).right); - } + // Handle certain special assignment kinds, which happen to union across multiple declarations: + // * module.exports = expr + // * exports.p = expr + // * this.p = expr + // * className.prototype.method = expr + if (declaration.kind === SyntaxKind.BinaryExpression || + declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { + type = getUnionType(map(symbol.declarations, + decl => decl.kind === SyntaxKind.BinaryExpression ? + checkExpressionCached((decl).right) : + checkExpressionCached((decl.parent).right))); } if (type === undefined) {