.d.ts在TypeScript 2.6.1之后没有编译

lil*_*zek 3 typescript

我使用TypeScript版本2.5与此环境模块的suncalc包:

// Note: incomplete
// https://www.npmjs.com/package/suncalc

declare module "suncalc" {
  interface suncalcResult {
    solarNoon: Date;
    nadir: Date;
    sunrise: Date;
    sunset: Date;
    sunriseEnd: Date;
    sunsetStart: Date;
    dawn: Date;
    dusk: Date;
    nauticalDawn: Date;
    nauticalDusk: Date;
    nightEnd: Date;
    night: Date;
    goldenHourEnd: Date;
    goldenHour: Date;
  }

  function sunCalc(date: Date, latitude: number, longitude: number): suncalcResult;

  export = { // COMPLAINING HERE <--------------------------- line 24
    getTimes: sunCalc
  };
}
Run Code Online (Sandbox Code Playgroud)

在TypeScript 2.5中,我调用suncalc.d.ts并编译了此文件,没有错误.当我升级到2.6时,它开始归咎于:

message: 'The expression of an export assignment must be an identifier or qualified name in an ambient context.'
at: '24,12'
source: 'ts'
Run Code Online (Sandbox Code Playgroud)

但是,在TypeScript更改日志中,没有任何关于环境模块的更改.

为什么现在不编译?我该如何在TS2.6中编写导出?

art*_*tem 6

这在破坏性更改页面上提到.像所讨论的那样的导出分配是可执行代码,并且2.6.1 在执行一般规则时更严格,即在声明文件中不允许执行代码.

重写声明的建议方法是声明一个具有显式类型的变量并导出变量:

const _exported: { getTimes: sunCalc };
export = _exported;
Run Code Online (Sandbox Code Playgroud)