【发布时间】:2016-06-22 02:08:27
【问题描述】:
我正在尝试在 TypeScript 中扩展一个类。我在编译时不断收到此错误:“提供的参数与调用目标的任何签名都不匹配。”我尝试将 super 调用中的 artist.name 属性引用为 super(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 getArtist(artist: Human){
console.log(artist.name)
}
let Banksy = new Artist(
"Banksy",
40,
"Politcal Graffitti",
"England / Wolrd"
)
getArtist(Banksy);
【问题讨论】:
标签: javascript oop typescript