如何在接口上扩展属性

时间:2017-01-18 22:14:35

标签: typescript webstorm

我有两个接口。接口B是通用接口,而接口export interface A { foo: { bar1: any; bar2: any; } } export interface B extends A { foo: { bar3: any; } specialBar: Function } 是一种较少使用的特殊扩展。

B.foo

如何设置A.foo ('bar1', 'bar2')继承B.foo上的属性,同时扩展('bar3')以包含新属性A.foo

有没有办法扩展A.foo而不给Incompatible override for member from interface A自己的接口?

目前,WebStorm正在抛出错误:[TestMethod] [DeploymentItem(@"MyProject.Tests\TestFiles\file.txt")] public void MyTest() { var myfile= "file.txt"; Assert.IsTrue( File.Exists(myfile), "Deployment failed: {0} did not get deployed.", myfile ); }

1 个答案:

答案 0 :(得分:0)

可能不是你真正想要的,但有这个黑客:

const _a = undefined as A

export interface B extends A {
  foo: typeof _a.foo & {
    bar3: any;
  }
  specialBar: Function
}