TS2611

error TS2611: ‘name‘ is defined as a property in class ‘Person‘, but is overridden here in ‘MyPerson‘ as an accessor.

Broken Code ❌

1
2
3
4
5
6
7
8
9
abstract class Person {
name: string = "unknown";
}

class MyPerson extends Person {
get name(): string {
return `${super.name.toUpperCase}`;
}
}

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:

1
2
3
4
5
6
7
8
9
abstract class Person {
accessor name: string = "unknown";
}

class MyPerson extends Person {
get name(): string {
return `${super.name.toUpperCase}`;
}
}