【发布时间】:2020-03-16 18:35:37
【问题描述】:
我在我的项目中同时安装了webpack-bundle-analyzer 和@types/webpack-bundle-analyzer,我可以说提供的声明工作正常,但是这些声明并不完整。除了BundleAnalyzerPlugin类,库还导出了start()函数。
如何扩充现有声明以添加start() 函数?
我尝试创建以下文件:./types/webpack-bundle-analyzer/index.d.ts,其内容如下:
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
declare module 'webpack-bundle-analyzer' {
export function start(
bundleStats: any,
opts: BundleAnalyzerPlugin.Options
);
}
但由于某种原因它并没有改变任何东西。
我的tsconfig.json 设置了typeRoots 选项:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types/",
"types/"
]
}
}
我收到以下错误:
src/somefile.ts:4:10 - error TS2305: Module '"../../node_modules/@types/webpack-bundle-analyzer"' has no exported member 'start'.
4 import { start } from 'webpack-bundle-analyzer';
原始声明是这样定义的:
import { Plugin, Compiler } from 'webpack';
export namespace BundleAnalyzerPlugin {
interface Options { … }
}
export class BundleAnalyzerPlugin extends Plugin {
constructor(options?: BundleAnalyzerPlugin.Options);
apply(compiler: Compiler): void;
}
【问题讨论】:
-
模块扩充应作为常规文件/模块包含
标签: typescript typescript-typings