我有一个基本接口,我希望我的子接口看起来像基本接口。 我该怎么办?
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
。
谢谢
答案 0 :(得分:0)
interface ChildInterface extends BaseInterface {
someOtherProp:string;
}
const someItem : ChildInterface = //...
console.log(someItem.api.firstName);
console.log(someItem.someOtherProp);