【发布时间】:2020-08-10 20:34:56
【问题描述】:
我的项目中有一个对象。这是架构:
IObject : {
prop1: number;
prop2: number;
}
对于 90% 的使用情况,这是我想要的类型。但有一些情况要求我还为每个属性返回一个字符串。因此,对于某些情况,我想要一个返回的接口:
object: IObjectWithStrings // Here I want to add string to each property as acceptable type.
// Something like
object: IObjects extends string
我该怎么做?我可以为此创建一个新接口,但我宁愿拥有原始接口并对其进行扩展。谢谢!!
【问题讨论】:
标签: typescript object interface