中級 › incorrectly implements interface の原因と直し方 › パターン1
incorrectly implements interface の原因と直し方
クラスがimplementsで宣言したinterfaceのメンバー(メソッドやプロパティ)を実装し忘れたときに出るエラーです。
1 interface Greeter { 2 greet(): string; 3 } 4 class Bot implements Greeter {___________________________________ ^ 5 } 6 console.log(new Bot());
main.ts(4,7): error TS2420: Class 'Bot' incorrectly implements interface 'Greeter'.
空欄を埋めてコンパイルを通す
GreeterはgreetメソッドをBotに要求します。実装しないままimplementsすると、契約違反としてエラーになります。
次の問題