diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4c3a98b12dc..a0675e957dd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4260,13 +4260,11 @@ namespace ts { if (isPropertyAccessExpression(expression.left) && expression.left.expression.kind === SyntaxKind.ThisKeyword) { const thisContainer = getThisContainer(expression, /*includeArrowFunctions*/ false); - const isPrototypeProperty = isBinaryExpression(thisContainer.parent) && - getSpecialPropertyAssignmentKind(thisContainer.parent) === SpecialPropertyAssignmentKind.PrototypeProperty; // Properties defined in a constructor (or javascript constructor function) don't get undefined added. // Function expressions that are assigned to the prototype count as methods. if (thisContainer.kind === SyntaxKind.Constructor || thisContainer.kind === SyntaxKind.FunctionDeclaration || - (thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypeProperty)) { + (thisContainer.kind === SyntaxKind.FunctionExpression && !isPrototypePropertyAssignment(thisContainer.parent))) { definedInConstructor = true; } else { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a5ba7c30cd2..69249952166 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1656,6 +1656,10 @@ namespace ts { return SpecialPropertyAssignmentKind.None; } + export function isPrototypePropertyAssignment(node: Node): boolean { + return isBinaryExpression(node) && getSpecialPropertyAssignmentKind(node) === SpecialPropertyAssignmentKind.PrototypeProperty; + } + export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression): boolean { return isInJavaScriptFile(expr) && expr.parent && expr.parent.kind === SyntaxKind.ExpressionStatement &&