mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Merge pull request #8712 from Microsoft/readonly_assignment_in_constructor
Allow assignment to readonly parameter property within the constructor
This commit is contained in:
@@ -11877,8 +11877,14 @@ namespace ts {
|
||||
if (symbol.flags & SymbolFlags.Property &&
|
||||
(expr.kind === SyntaxKind.PropertyAccessExpression || expr.kind === SyntaxKind.ElementAccessExpression) &&
|
||||
(expr as PropertyAccessExpression | ElementAccessExpression).expression.kind === SyntaxKind.ThisKeyword) {
|
||||
// Look for if this is the constructor for the class that `symbol` is a property of.
|
||||
const func = getContainingFunction(expr);
|
||||
return !(func && func.kind === SyntaxKind.Constructor && func.parent === symbol.valueDeclaration.parent);
|
||||
if (!(func && func.kind === SyntaxKind.Constructor))
|
||||
return true;
|
||||
// If func.parent is a class and symbol is a (readonly) property of that class, or
|
||||
// if func is a constructor and symbol is a (readonly) parameter property declared in it,
|
||||
// then symbol is writeable here.
|
||||
return !(func.parent === symbol.valueDeclaration.parent || func === symbol.valueDeclaration.parent);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user