Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Fix missing type TypedChainedMap.getOrCompute (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
opl- authored and edmorley committed Dec 21, 2019
1 parent 7fb3c67 commit df193ec
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
37 changes: 37 additions & 0 deletions types/test/webpack-chain-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class ResolvePluginImpl extends webpack.ResolvePlugin {
apply(resolver: Resolver): void {}
}

function expectType<T>(value: T) {}

const config = new Config();

config
Expand Down Expand Up @@ -322,3 +324,38 @@ config

.merge({})
.toConfig();

// Test TypedChainedMap
const entryPoints = config.entryPoints;

expectType<typeof entryPoints>(entryPoints.clear());
expectType<typeof entryPoints>(entryPoints.delete('key'));
expectType<boolean>(entryPoints.has('key'));
expectType<Config.EntryPoint>(entryPoints.get('key'));
expectType<Config.EntryPoint>(entryPoints.getOrCompute('key', () => new Config.EntryPoint()));
expectType<typeof entryPoints>(entryPoints.set('key', new Config.EntryPoint()));
expectType<typeof entryPoints>(entryPoints.merge({
key: new Config.EntryPoint(),
}));
expectType<Record<string, Config.EntryPoint>>(entryPoints.entries());
expectType<typeof entryPoints>(entryPoints.when(true, (val) => {
expectType<typeof entryPoints>(val);
}, (val) => {
expectType<typeof entryPoints>(val);
}));

// Test TypedChainedSet
const extensions = config.resolve.extensions;

expectType<typeof extensions>(extensions.add('.txt'));
expectType<typeof extensions>(extensions.prepend('.txt'));
expectType<typeof extensions>(extensions.clear());
expectType<typeof extensions>(extensions.delete('.txt'));
expectType<boolean>(extensions.has('.txt'));
expectType<typeof extensions>(extensions.merge(['.txt']));
expectType<string[]>(extensions.values());
expectType<typeof extensions>(extensions.when(true, (val) => {
expectType<typeof extensions>(val);
}, (val) => {
expectType<typeof extensions>(val);
}));

0 comments on commit df193ec

Please sign in to comment.