上級 › 同名interfaceのマージで型が矛盾した原因と直し方 › パターン5
同名interfaceのマージで型が矛盾した原因と直し方
同じ名前のinterfaceを複数回宣言すると、TypeScriptはそれらを自動的に1つに合成します(宣言のマージ)。
1 interface Flag { 2 enabled: boolean; 3 } 4 interface Flag { 5 enabled: _______; ^ 6 } 7 console.log("ok");
main.ts(5,3): error TS2717: Subsequent property declarations must have the same type.
空欄を埋めてコンパイルを通す
enabledの型は最初の宣言でboolean型と決まっています。あとから違う型にすると合成できません。
次の問題