我是打字稿的新手,我有两个班.在父类我有:
abstract class Component {
public deps: any = {};
public props: any = {};
public setProp(prop: string): any {
return <T>(val: T): T => {
this.props[prop] = val;
return val;
};
}
}
Run Code Online (Sandbox Code Playgroud)
在孩子班我有:
class Post extends Component {
public toggleBody: string;
constructor() {
this.toggleBody = this.setProp('showFullBody');
}
public showMore(): boolean {
return this.toggleBody(true);
}
public showLess(): boolean {
return this.toggleBody(false);
}
}
Run Code Online (Sandbox Code Playgroud)
showMore和ShowLess都给出了错误,"无法调用类型缺少调用签名的表达式".
但是,我认为setProp返回DOES的函数有一个调用签名?我想我误解了关于函数类型的重要事情,但我不知道它是什么.
谢谢!