增加导出默认值的外部模块

Pel*_*obs 5 typescript typescript-typings

如何增强导出默认值的模块?例如:

默认模块.d.ts

declare namespace TheNamespace {
  interface TheInterface {
    prop: number
  }
}

export default TheNamespace
Run Code Online (Sandbox Code Playgroud)

应用程序.ts

import theModule from "./default-module"

declare module "./default-module" {
  interface AugmentedInterface {
    augmentedProp: number
  }
}

let theNormalVariable: theModule.TheInterface          // fine
let theAugmentedVariable: theModule.AugmentedInterface // errors
Run Code Online (Sandbox Code Playgroud)

但是,当您export =而不是 时export default,这似乎工作正常。(正如本期所讨论的)

等于模块.d.ts

declare namespace TheNamespace {
  interface TheInterface {
    prop: number
  }
}

export = TheNamespace
Run Code Online (Sandbox Code Playgroud)

应用程序.ts

import theModule = require("./equals-module")

declare module "./equals-module" {
  interface AugmentedInterface {
    augmentedProp: number
  }
}

let theNormalVariable: theModule.TheInterface          // fine
let theAugmentedVariable: theModule.AugmentedInterface // fine
Run Code Online (Sandbox Code Playgroud)