从另一个模块扩展打字稿接口

Extending typescript interface from another module

我正在使用 Highcharts 类型,我需要扩展它定义的几个 object/interfaces 以添加我自己的一些属性。例如

declare namespace Chart {  
  interface ChartOptions extends Highcharts.ChartOptions {
    series: ResourceSeries[];
  }
}

chart.component.ts

import ChartOptions = Chart.ChartOptions;
export class ChartComponent {
}

这没有给我 "Chart is not defined"。同时,如果在另一个使用 ChartComponent 指令的(主)模块中使用,则导入有效。

如何导入接口,扩展它并re-exporting?

// chart-options.extended.ts
import { ChartOptions as ChartOptionsBase } from 'highcharts'

interface ChartOptionsExtended extends ChartOptionsBase {
    extensionProperty: string
}

export { ChartOptionsExtended as ChartOptions }

不确定您使用的 typings/types 系统,但我使用的是 Typescript 2.0 样式,它不使用 "ambient" 打字:

npm install --save highcharts @types/highcharts

问题似乎是我无法在模块内使用命名空间。切换到单独的 non-d.ts 文件中的普通接口导出是可行的,因为现在每个接口都与模块的其余部分打包在一起,可以这样导入。