TS2612
Property
myVariablewill overwrite the base property inMyBaseClass. If this is intentional, add an initializer. Otherwise, add adeclaremodifier or remove the redundant declaration.
Broken Code ❌
class MyBaseClass {
myVariable = '123';
}
export class MyExtendedClass extends MyBaseClass {
myVariable;
logMyVariable = () => {
console.log(this.myVariable);
};
}Fixed Code ✔️
If you don't intend to reinitialize an inherited variable, you can simply avoid it to be redeclared:
class MyBaseClass {
myVariable = '123';
}
export class MyExtendedClass extends MyBaseClass {
logMyVariable = () => {
console.log(this.myVariable);
};
}