【发布时间】:2018-09-23 11:05:58
【问题描述】:
http://www.typescriptlang.org/docs/handbook/interfaces.html 的 “接口扩展类” 部分下的信息表明
接口甚至继承基类的私有成员和受保护成员 类。
但是,当我尝试时,TypeScript 提示错误,指出派生类错误地实现了接口 - 并且基类的 private 和 protected 成员在派生类。
以下是代码:
class View {
private content: any;
protected presentation: string;
public render() {
console.log("View::render()");
console.log("content: ", this.content);
console.log("presentation: ", this.presentation);
}
constructor(c: string, p: string) {
this.content = c;
this.presentation = p;
}
}
interface ViewShadow extends View {}
class MobileDisplay implements ViewShadow {
private content: any;
protected presentation: string;
public render() {
console.log("View::render()");
console.log("content: ", this.content);
console.log("presentation: ", this.presentation);
}
constructor(c: string, p: string) {
this.content = c;
this.presentation = p;
}
}
【问题讨论】:
-
你能分享一下确切的错误信息吗?