我想在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的答案。 –