TypeScript 接口可以扩展到另一个接口吗?

Can a TypeScript interface be spread into another interface?

在 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;
}

您可以只使用继承来做到这一点:

interface IA {
    one: number;
    two: number;
}
interface IC {
    other: number;
    four: number;
}
interface IB extends IA, IC {
    three: number;
}