Skip to content

Commit c40c437

Browse files
chore: fix types (#4434)
1 parent c77dbbe commit c40c437

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"ts-loader": "^9.3.1",
9292
"ts-node": "^10.9.1",
9393
"typescript": "^5.0.4",
94-
"webpack": "^5.94.0",
94+
"webpack": "^5.99.1",
9595
"webpack-bundle-analyzer": "^4.5.0",
9696
"webpack-dev-server": "^5.1.0"
9797
}

packages/serve/src/index.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
55
const WEBPACK_DEV_SERVER_PACKAGE = process.env.WEBPACK_DEV_SERVER_PACKAGE || "webpack-dev-server";
66

77
type Problem = NonNullable<ReturnType<(typeof cli)["processArguments"]>>[0];
8+
type StringsKeys<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];
89

910
class ServeCommand {
1011
async apply(cli: IWebpackCLI): Promise<void> {
@@ -174,22 +175,23 @@ class ServeCommand {
174175
{},
175176
);
176177
const result = { ...(compilerForDevServer.options.devServer || {}) };
177-
const problems = (
178-
cli.webpack.cli && typeof cli.webpack.cli.processArguments === "function"
179-
? cli.webpack.cli
180-
: DevServer.cli
181-
).processArguments(args, result, values);
178+
const problems = cli.webpack.cli.processArguments(args, result, values);
182179

183180
if (problems) {
184-
const groupBy = (xs: Problem[], key: keyof Problem) => {
181+
const groupBy = <K extends keyof Problem & StringsKeys<Problem>>(
182+
xs: Problem[],
183+
key: K,
184+
) => {
185185
return xs.reduce((rv: { [key: string]: Problem[] }, x: Problem) => {
186-
(rv[x[key]] = rv[x[key]] || []).push(x);
186+
const path = x[key];
187+
188+
(rv[path] = rv[path] || []).push(x);
187189

188190
return rv;
189191
}, {});
190192
};
191193

192-
const problemsByPath = groupBy(problems, "path");
194+
const problemsByPath = groupBy<"path">(problems, "path");
193195

194196
for (const path in problemsByPath) {
195197
const problems = problemsByPath[path];

packages/webpack-cli/src/types.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ interface WebpackCLIBuiltInFlag {
133133
value: string,
134134
previous: Record<string, BasicPrimitive | object>,
135135
) => Record<string, BasicPrimitive | object>;
136-
configs?: Partial<FlagConfig>[];
136+
configs?: ArgumentConfig[];
137137
negative?: boolean;
138138
multiple?: boolean;
139139
valueName?: string;
@@ -191,12 +191,17 @@ type LoadableWebpackConfiguration = PotentialPromise<
191191
type CallableWebpackConfiguration = (env: Env | undefined, argv: Argv) => WebpackConfiguration;
192192
type WebpackCompiler = Compiler | MultiCompiler;
193193

194-
type FlagType = boolean | "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset";
194+
type EnumValueObject = { [key: string]: EnumValue };
195+
type EnumValueArray = EnumValue[];
196+
type EnumValue = string | number | boolean | EnumValueObject | EnumValueArray | null;
195197

196-
type FlagConfig = {
197-
negatedDescription: string;
198-
type: FlagType;
199-
values: FlagType[];
198+
type ArgumentConfig = {
199+
description?: string;
200+
negatedDescription?: string;
201+
path?: string;
202+
multiple?: boolean;
203+
type: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset";
204+
values?: EnumValue[];
200205
};
201206

202207
type FileSystemCacheOptions = WebpackConfiguration & {
@@ -324,7 +329,8 @@ export {
324329
LoadableWebpackConfiguration,
325330
DynamicImport,
326331
FileSystemCacheOptions,
327-
FlagConfig,
332+
ArgumentConfig,
333+
EnumValue,
328334
ImportLoaderError,
329335
Instantiable,
330336
JsonExt,

packages/webpack-cli/src/webpack-cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
LoadableWebpackConfiguration,
2525
DynamicImport,
2626
FileSystemCacheOptions,
27-
FlagConfig,
27+
EnumValue,
2828
ImportLoaderError,
2929
Instantiable,
3030
JsonExt,
@@ -1646,7 +1646,7 @@ class WebpackCLI implements IWebpackCLI {
16461646
return accumulator;
16471647
}
16481648
},
1649-
<FlagConfig["values"]>[],
1649+
<EnumValue[]>[],
16501650
);
16511651

16521652
if (possibleValues.length > 0) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10241,10 +10241,10 @@ webpack-sources@^3.2.3:
1024110241
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
1024210242
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==
1024310243

10244-
webpack@^5.94.0:
10245-
version "5.98.0"
10246-
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.98.0.tgz#44ae19a8f2ba97537978246072fb89d10d1fbd17"
10247-
integrity sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA==
10244+
webpack@^5.99.1:
10245+
version "5.99.1"
10246+
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.99.1.tgz#8847e847678bcc3d1fc93a30741bbd78bccc028c"
10247+
integrity sha512-o9gY7ibHPFxLjF6NtvQ6+5CGknsPTRllsL6SEnqR2Zhjk02hiIioJYLS7dvrWaykrRbbmhvDeKp36mKHNbKYiw==
1024810248
dependencies:
1024910249
"@types/eslint-scope" "^3.7.7"
1025010250
"@types/estree" "^1.0.6"

0 commit comments

Comments
 (0)