Reputation: 28611
I've installed both webpack-bundle-analyzer
and @types/webpack-bundle-analyzer
in my project and I can say that provided declarations are working correctly, however, those declarations are not complete. Besides BundleAnalyzerPlugin
class, the library also exports the start()
function.
How do I augment the existing declaration to add start()
function to it?
I've tried creating the following file: ./types/webpack-bundle-analyzer/index.d.ts
with the following content:
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
declare module 'webpack-bundle-analyzer' {
export function start(
bundleStats: any,
opts: BundleAnalyzerPlugin.Options
);
}
But it doesn't change anything for some reason.
My tsconfig.json
has typeRoots
option set:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types/",
"types/"
]
}
}
I'm getting the following error:
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';
Original declaration is defined like this:
import { Plugin, Compiler } from 'webpack';
export namespace BundleAnalyzerPlugin {
interface Options { … }
}
export class BundleAnalyzerPlugin extends Plugin {
constructor(options?: BundleAnalyzerPlugin.Options);
apply(compiler: Compiler): void;
}
Upvotes: 0
Views: 656
Reputation: 28611
The problem was with the way my tsconfig.json
was written:
{
"compilerOptions": {
"typeRoots": [
"node_modules/@types/",
"types/"
]
}
}
I needed to change the order of search directories, so that my local declarations took precedence over the ones imported from node_modules
:
{
"compilerOptions": {
"typeRoots": [
"types/",
"node_modules/@types/"
]
}
}
Upvotes: 2