您可以扩大全局范围并使用接口合并来重新打开NodeModule
接口并添加缺少的hot
属性。
import webpack = require("webpack");
declare global {
interface NodeModule {
hot: {
accept(dependencies: string[], callback: (updatedDependencies: string[]) => void): void;
accept(dependency: string, callback: () => void): void;
accept(errHandler?: (err: any) => void): void;
decline(dependencies: string[]): void;
decline(dependency: string): void;
decline(): void;
dispose(callback: (data: any) => void): void;
addDisposeHandler(callback: (data: any) => void): void;
removeDisposeHandler(callback: (data: any) => void): void;
// ...
}
}
}
但实际上,这种扩充可能应该在 Webpack 声明文件本身中完成。