我已经在我的项目中同时安装了webpack-bundle-analyzer和@types/webpack-bundle-analyzer,而且我可以说,只要声明工作正常,那么这些声明是不完整的。除了BundleAnalyzerPlugin类之外,库还导出start()函数。
如何在现有声明中添加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;
}发布于 2020-03-16 10:35:37
问题在于我的tsconfig.json的编写方式:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types/",
"types/"
]
}
}我需要更改搜索目录的顺序,以便本地声明优先于从node_modules导入的声明。
{
"compilerOptions": {
"typeRoots": [
"types/",
"node_modules/@types/"
]
}
}https://stackoverflow.com/questions/60704234
复制相似问题