中級 › インデックスシグネチャと矛盾する型のプロパティを宣言するとエラーになる › パターン2
インデックスシグネチャと矛盾する型のプロパティを宣言するとエラーになる
[key: string]: numberのようなインデックスシグネチャを持つinterfaceでは、個別に宣言する具体的なプロパティも、インデックスシグネチャの型と互換性がなければ宣言できません。
1 interface Scores { 2 [key: string]: number; 3 ______________; ^ 4 } 5 console.log("ok");
main.ts(3,3): error TS2411: Property 'label' of type 'boolean' is not assignable to 'string' index type 'number'.
空欄を埋めてコンパイルを通す
labelをboolean型で宣言すると、number型を要求するインデックスシグネチャと矛盾します。
次の問題