初級 › Property does not exist on type の原因と直し方 › パターン2
Property does not exist on type の原因と直し方
型に定義されていないプロパティ名でアクセスしようとしたときに出るエラーです。
1 interface Point { 2 x: number; 3 y: number; 4 } 5 const p: Point = { x: 1, y: 2 }; 6 console.log(p._); ^
main.ts(6,15): error TS2339: Property 'z' does not exist on type 'Point'.
空欄を埋めてコンパイルを通す
Pointにはxとyしかありません。zというプロパティは定義されていません。
次の問題