mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 22:15:05 -05:00
Always error when property overrides accessor or vice versa
Previously this was only an error when useDefineForClassFields: true, but now it's an error for all code. This is a rare mistake to make, and usually only occurs in code written before `readonly` was available. Codefix to come in subsequent commits.
This commit is contained in:
@@ -33373,8 +33373,7 @@ namespace ts {
|
||||
const derivedPropertyFlags = derived.flags & SymbolFlags.PropertyOrAccessor;
|
||||
if (basePropertyFlags && derivedPropertyFlags) {
|
||||
// property/accessor is overridden with property/accessor
|
||||
if (!compilerOptions.useDefineForClassFields
|
||||
|| baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
|
||||
if (baseDeclarationFlags & ModifierFlags.Abstract && !(base.valueDeclaration && isPropertyDeclaration(base.valueDeclaration) && base.valueDeclaration.initializer)
|
||||
|| base.valueDeclaration && base.valueDeclaration.parent.kind === SyntaxKind.InterfaceDeclaration
|
||||
|| derived.valueDeclaration && isBinaryExpression(derived.valueDeclaration)) {
|
||||
// when the base property is abstract or from an interface, base/derived flags don't need to match
|
||||
@@ -33390,7 +33389,7 @@ namespace ts {
|
||||
Diagnostics._0_is_defined_as_a_property_in_class_1_but_is_overridden_here_in_2_as_an_accessor;
|
||||
error(getNameOfDeclaration(derived.valueDeclaration) || derived.valueDeclaration, errorMessage, symbolToString(base), typeToString(baseType), typeToString(type));
|
||||
}
|
||||
else {
|
||||
else if (compilerOptions.useDefineForClassFields) {
|
||||
const uninitialized = find(derived.declarations, d => d.kind === SyntaxKind.PropertyDeclaration && !(d as PropertyDeclaration).initializer);
|
||||
if (uninitialized
|
||||
&& !(derived.flags & SymbolFlags.Transient)
|
||||
|
||||
Reference in New Issue
Block a user