小编ale*_*ett的帖子

使用TypeScript super()

我试图在TypeScript中扩展一个类.我在编译时一直收到这个错误:'提供的参数与调用目标的任何签名都不匹配.我已经尝试在超级调用中引用artist.name属性作为超级(名称)但是不起作用.

我们将非常感谢您提出的任何想法和解释.谢谢 - 亚历克斯.

class Artist {
  constructor(
    public name: string,
    public age: number,
    public style: string,
    public location: string
  ){
    console.log(`instantiated ${name}, whom is ${age} old, from ${location}, and heavily regarded in the ${style} community`);
  }
}

class StreetArtist extends Artist {
  constructor(
    public medium: string,
    public famous: boolean,
    public arrested: boolean,
    public art: Artist
  ){
    super();
    console.log(`instantiated ${this.name}. Are they famous? ${famous}. Are they locked up? ${arrested}`);
  }
}

interface Human {
  name: string,
  age: number
}

function …
Run Code Online (Sandbox Code Playgroud)

javascript oop typescript

19
推荐指数
1
解决办法
2万
查看次数

标签 统计

javascript ×1

oop ×1

typescript ×1