[英]How to “interface” an interface in typescript?
我有一个基本界面,我希望我的子界面看起来像基本界面。 我该怎么做?
interface BaseInterface {
api: { [key: string]: string };
ui: { [key: string]: string };
}
interface ChildInterface {
// I want to force this interface to have the same shape as BaseInterface
// like so :
api: { firstName: string };
ui: { firstName: string };
}
我尝试使用type ChildInterface = BaseInterface
但我无法设法自定义我的ChildInterface
。
谢谢
interface ChildInterface extends BaseInterface {
someOtherProp:string;
}
const someItem : ChildInterface = //...
console.log(someItem.api.firstName);
console.log(someItem.someOtherProp);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.