diff --git a/types/index.d.ts b/types/index.d.ts index e887a67..127b0eb 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -14,6 +14,7 @@ declare namespace __Config { delete(key: string): this; has(key: string): boolean; get(key: string): Value; + getOrCompute(key: string, compute: () => Value): Value; set(key: string, value: Value): this; merge(obj: { [key: string]: Value }): this; entries(): { [key: string]: Value }; diff --git a/types/test/webpack-chain-tests.ts b/types/test/webpack-chain-tests.ts index 74e8e01..8c1dfe8 100644 --- a/types/test/webpack-chain-tests.ts +++ b/types/test/webpack-chain-tests.ts @@ -10,6 +10,8 @@ class ResolvePluginImpl extends webpack.ResolvePlugin { apply(resolver: Resolver): void {} } +function expectType(value: T) {} + const config = new Config(); config @@ -322,3 +324,38 @@ config .merge({}) .toConfig(); + +// Test TypedChainedMap +const entryPoints = config.entryPoints; + +expectType(entryPoints.clear()); +expectType(entryPoints.delete('key')); +expectType(entryPoints.has('key')); +expectType(entryPoints.get('key')); +expectType(entryPoints.getOrCompute('key', () => new Config.EntryPoint())); +expectType(entryPoints.set('key', new Config.EntryPoint())); +expectType(entryPoints.merge({ + key: new Config.EntryPoint(), +})); +expectType>(entryPoints.entries()); +expectType(entryPoints.when(true, (val) => { + expectType(val); +}, (val) => { + expectType(val); +})); + +// Test TypedChainedSet +const extensions = config.resolve.extensions; + +expectType(extensions.add('.txt')); +expectType(extensions.prepend('.txt')); +expectType(extensions.clear()); +expectType(extensions.delete('.txt')); +expectType(extensions.has('.txt')); +expectType(extensions.merge(['.txt'])); +expectType(extensions.values()); +expectType(extensions.when(true, (val) => { + expectType(val); +}, (val) => { + expectType(val); +}));