初級 › 必須プロパティの書き忘れエラーの原因と直し方 › パターン5
必須プロパティの書き忘れエラーの原因と直し方
interfaceで定義した必須プロパティを、オブジェクトリテラルで指定し忘れたときに出るエラーです。
1 interface Pair { 2 a: number; 3 b: number; 4 } 5 const p: Pair = ______________; ^ 6 console.log(p.b);
main.ts(5,7): error TS2741: Property 'b' is missing in type '{ a: number; }' but required in type 'Pair'.
空欄を埋めてコンパイルを通す
Pairはaとbの両方が必須です。bを省略すると代入できません。
次の問題