如何扩充导出默认值的模块?例如:
默认-module.d.ts
declare namespace TheNamespace {
interface TheInterface {
prop: number
}
}
export default TheNamespace
app.ts
import theModule from "./default-module"
declare module "./default-module" {
interface AugmentedInterface {
augmentedProp: number
}
}
let theNormalVariable: theModule.TheInterface // fine
let theAugmentedVariable: theModule.AugmentedInterface // errors
但是,当您的export =
代替export default
时,这似乎工作正常。 (如this issue中所述)
等于-module.d.ts
declare namespace TheNamespace {
interface TheInterface {
prop: number
}
}
export = TheNamespace
app.ts
import theModule = require("./equals-module")
declare module "./equals-module" {
interface AugmentedInterface {
augmentedProp: number
}
}
let theNormalVariable: theModule.TheInterface // fine
let theAugmentedVariable: theModule.AugmentedInterface // fine