【发布时间】:2018-12-01 22:32:40
【问题描述】:
在 JavaScript 中,可以使用扩展语法将一个对象扩展为另一个对象:
const a = {one: 1, two: 2}
const b = {...a, three: 3} // = {one: 1, two: 2, three: 3}
有没有办法以这种方式将 typescript 界面传播到另一个界面?
interface IA {
one: number;
two: number;
}
interface IB {
...IA; // Does not work like this
three: number;
}
所以结果界面IB 看起来像这样:
{
one: number;
two: number;
three: number;
}
【问题讨论】:
标签: typescript object interface spread-syntax