クラスをTypeScriptで拡張しようとしています。私はコンパイル時にこのエラーを受け取ります: '提供されたパラメータが呼び出しターゲットのシグネチャと一致しません。'私はsuper(name)としてsuper.allでartist.nameプロパティを参照しようとしましたが、動作しません。TypeScriptを使用するsuper()
あなたが持っている可能性のあるアイデアや説明は非常に高く評価されます。ありがとう - アレックス。
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の回答をご覧ください。 –