中級 › abstractクラスを直接newした原因と直し方 › パターン4
abstractクラスを直接newした原因と直し方
abstractを付けたクラスは、そのままnewでインスタンス化することができません。
1 abstract class Instrument { 2 abstract play(): string; 3 } 4 class Piano extends Instrument { 5 play(): string { return "plink"; } 6 } 7 const x = new __________(); ^ 8 console.log(x);
main.ts(7,11): error TS2511: Cannot create an instance of an abstract class.
空欄を埋めてコンパイルを通す
Instrumentはabstractクラスなので直接newできません。
次の問題