我想在TypeScript中扩展一个类。我在编译时收到这个错误:'提供的参数不匹配调用目标的任何签名'。我已经尝试在超级调用中引用artist.name属性作为超级(名称),但不起作用。使用TypeScript超级()
您可能会有任何想法和解释将不胜感激。谢谢 - 亚历克斯。
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);
**解答:请参阅下面的@mollwe的答案。 –