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