TS2611
'name' is defined as a property in class 'Person', but is overridden here in 'MyPerson' as an accessor.
Broken Code ❌
abstract class Person {
name: string = 'unknown';
}
class MyPerson extends Person {
get name(): string {
return `${super.name.toUpperCase}`;
}
}Fixed Code ✔️
Getters and setters are property accessors, so you have to make sure that you don't mix property definitions with property accessor definitions. Using the accessor keyword, you can turn a property into a property accessor:
abstract class Person {
accessor name: string = 'unknown';
}
class MyPerson extends Person {
get name(): string {
return `${super.name.toUpperCase}`;
}
}