Reputation: 10916
When I try to override a parent method and I use super inside, I get this error:
error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword.
return super.toJson(["password", ...blacklist]);
This is an example:
abstract class BaseUser {
name: string;
constructor(name: string) {
this.name = name;
}
toJson = () => {
return Object.assign({}, this);
}
}
class MyUser {
...
toJson = (blacklist) => {
...
const obj = super.toJson();
...
}
}
Don't know what I'm doing wrong...
Upvotes: 2
Views: 7917
Reputation: 155
As @Titian Cernicova-Dragomir said in the comments, you should use method instead. You can check these answers:
Inheritance method call triggers Typescript compiler error
Error when performing Inheritance in TypeScript
Upvotes: 6