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

Fix types for TypedChainedMap.getOrCompute missing #221

Merged
merged 2 commits into from
Dec 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}));