Skip to content

Commit e911f52

Browse files
fix: no object types and less any types
1 parent d3809ae commit e911f52

File tree

65 files changed

+534
-368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+534
-368
lines changed

eslint.config.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,15 @@ export default [
350350
comment:
351351
"JsdocBlock:has(JsdocTypeName[value=/^(function|Function)$/])",
352352
message:
353-
"Please use provide types for function - `(a: number, b: number) -> number` instead `Function` or use `EXPECTED_FUNCTION` type"
353+
"Please use provide types for function - `(a: number, b: number) -> number` instead `Function`/`function` or use `EXPECTED_FUNCTION` type"
354+
},
355+
// No `Object`
356+
{
357+
comment:
358+
"JsdocBlock:has(JsdocTag[tag!=/^(typedef|template|param)$/]:has(JsdocTypeName[value=/^(Object|object)$/]))",
359+
message:
360+
"Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`/`object` or use `EXPECTED_OBJECT` type"
354361
}
355-
// No `Object` type
356-
// {
357-
// comment:
358-
// "JsdocBlock:has(JsdocTag[tag!=/^(typedef|template)$/]:has(JsdocTypeName[value=/^(object|Object)$/]))",
359-
// message:
360-
// "Please use provide types for object - `{ property: number:, result: () => number}` instead `Object` or use `EXPECTED_OBJECT` type"
361-
// },
362362
]
363363
}
364364
]

lib/Compilation.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ const { isSourceEqual } = require("./util/source");
297297
* @property {Record<string, string | string[]>=} related object of pointers to other assets, keyed by type of relation (only points from parent to child)
298298
*/
299299

300-
/** @typedef {KnownAssetInfo & Record<string, any>} AssetInfo */
300+
/** @typedef {KnownAssetInfo & Record<string, EXPECTED_ANY>} AssetInfo */
301301

302302
/** @typedef {{ path: string, info: AssetInfo }} InterpolatedPathAndAssetInfo */
303303

@@ -650,10 +650,9 @@ class Compilation {
650650
* @param {number} stage new stage
651651
* @param {() => AsArray<T>} getArgs get old hook function args
652652
* @param {string=} code deprecation code (not deprecated when unset)
653-
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
653+
* @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">> | undefined} fake hook which redirects
654654
*/
655655
const createProcessAssetsHook = (name, stage, getArgs, code) => {
656-
// @ts-expect-error For better compatibility we will avoid the optional type
657656
if (!this._backCompat && code) return;
658657
/**
659658
* @param {string} reason reason
@@ -880,36 +879,52 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
880879
beforeChunkAssets: new SyncHook([]),
881880
// TODO webpack 6 remove
882881
/** @deprecated */
883-
additionalChunkAssets: createProcessAssetsHook(
884-
"additionalChunkAssets",
885-
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
886-
() => [this.chunks],
887-
"DEP_WEBPACK_COMPILATION_ADDITIONAL_CHUNK_ASSETS"
888-
),
882+
additionalChunkAssets:
883+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
884+
(
885+
createProcessAssetsHook(
886+
"additionalChunkAssets",
887+
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
888+
() => [this.chunks],
889+
"DEP_WEBPACK_COMPILATION_ADDITIONAL_CHUNK_ASSETS"
890+
)
891+
),
889892

890893
// TODO webpack 6 deprecate
891894
/** @deprecated */
892-
additionalAssets: createProcessAssetsHook(
893-
"additionalAssets",
894-
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
895-
() => []
896-
),
895+
additionalAssets:
896+
/** @type {FakeHook<Pick<AsyncSeriesHook<[]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
897+
(
898+
createProcessAssetsHook(
899+
"additionalAssets",
900+
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
901+
() => []
902+
)
903+
),
897904
// TODO webpack 6 remove
898905
/** @deprecated */
899-
optimizeChunkAssets: createProcessAssetsHook(
900-
"optimizeChunkAssets",
901-
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
902-
() => [this.chunks],
903-
"DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS"
904-
),
906+
optimizeChunkAssets:
907+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
908+
(
909+
createProcessAssetsHook(
910+
"optimizeChunkAssets",
911+
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE,
912+
() => [this.chunks],
913+
"DEP_WEBPACK_COMPILATION_OPTIMIZE_CHUNK_ASSETS"
914+
)
915+
),
905916
// TODO webpack 6 remove
906917
/** @deprecated */
907-
afterOptimizeChunkAssets: createProcessAssetsHook(
908-
"afterOptimizeChunkAssets",
909-
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1,
910-
() => [this.chunks],
911-
"DEP_WEBPACK_COMPILATION_AFTER_OPTIMIZE_CHUNK_ASSETS"
912-
),
918+
afterOptimizeChunkAssets:
919+
/** @type {FakeHook<Pick<AsyncSeriesHook<[Set<Chunk>]>, "tap" | "tapAsync" | "tapPromise" | "name">>} */
920+
(
921+
createProcessAssetsHook(
922+
"afterOptimizeChunkAssets",
923+
Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE + 1,
924+
() => [this.chunks],
925+
"DEP_WEBPACK_COMPILATION_AFTER_OPTIMIZE_CHUNK_ASSETS"
926+
)
927+
),
913928
// TODO webpack 6 deprecate
914929
/** @deprecated */
915930
optimizeAssets: processAssetsHook,
@@ -2350,7 +2365,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
23502365
};
23512366
entryData[target].push(entry);
23522367
this.entries.set(
2353-
/** @type {NonNullable<EntryOptions["name"]>} */ (name),
2368+
/** @type {NonNullable<EntryOptions["name"]>} */
2369+
(name),
23542370
entryData
23552371
);
23562372
} else {
@@ -2367,7 +2383,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
23672383
continue;
23682384
}
23692385
if (entryData.options[key] === undefined) {
2370-
entryData.options[key] = /** @type {TODO} */ (options[key]);
2386+
/** @type {TODO} */
2387+
(entryData.options)[key] =
2388+
/** @type {NonNullable<EntryOptions[keyof EntryOptions]>} */
2389+
(options[key]);
23712390
} else {
23722391
return callback(
23732392
new WebpackError(
@@ -4679,7 +4698,7 @@ This prevents using hashes of each other and should be avoided.`);
46794698
/**
46804699
* @param {string} file file name
46814700
* @param {Source | ((source: Source) => Source)} newSourceOrFunction new asset source or function converting old to new
4682-
* @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
4701+
* @param {(AssetInfo | ((assetInfo?: AssetInfo) => AssetInfo | undefined)) | undefined} assetInfoUpdateOrFunction new asset info or function converting old to new
46834702
*/
46844703
updateAsset(
46854704
file,

lib/DelegatedModuleFactoryPlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const DelegatedModule = require("./DelegatedModule");
1313
/** @typedef {import("./DelegatedModule").SourceRequest} SourceRequest */
1414
/** @typedef {import("./DelegatedModule").Type} Type */
1515
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
16+
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
1617

1718
/**
1819
* @typedef {object} Options
@@ -22,7 +23,7 @@ const DelegatedModule = require("./DelegatedModule");
2223
* @property {DllReferencePluginOptions["type"]} type type
2324
* @property {DllReferencePluginOptions["extensions"]} extensions extensions
2425
* @property {DllReferencePluginOptions["scope"]} scope scope
25-
* @property {object=} associatedObjectForCache object for caching
26+
* @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
2627
*/
2728

2829
class DelegatedModuleFactoryPlugin {

lib/Dependency.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,10 @@ Dependency.NO_EXPORTS_REFERENCED = [];
333333
Dependency.EXPORTS_OBJECT_REFERENCED = [[]];
334334

335335
// TODO remove in webpack 6
336-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919
337336
Object.defineProperty(Dependency.prototype, "module", {
338337
/**
339338
* @deprecated
340-
* @returns {never} throws
339+
* @returns {EXPECTED_ANY} throws
341340
*/
342341
get() {
343342
throw new Error(
@@ -357,8 +356,11 @@ Object.defineProperty(Dependency.prototype, "module", {
357356
});
358357

359358
// TODO remove in webpack 6
360-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919
361359
Object.defineProperty(Dependency.prototype, "disconnect", {
360+
/**
361+
* @deprecated
362+
* @returns {EXPECTED_ANY} throws
363+
*/
362364
get() {
363365
throw new Error(
364366
"disconnect was removed from Dependency (Dependency no longer carries graph specific information)"

lib/DllReferencePlugin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
1818
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsContent} DllReferencePluginOptionsContent */
1919
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
2020
/** @typedef {import("./Compiler")} Compiler */
21+
/** @typedef {import("./Compiler").CompilationParams} CompilationParams */
2122
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
2223

2324
const validate = createSchemaValidation(
@@ -38,7 +39,7 @@ class DllReferencePlugin {
3839
constructor(options) {
3940
validate(options);
4041
this.options = options;
41-
/** @type {WeakMap<object, CompilationDataItem>} */
42+
/** @type {WeakMap<CompilationParams, CompilationDataItem>} */
4243
this._compilationData = new WeakMap();
4344
}
4445

lib/FileSystemInfo.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,8 @@ class SnapshotIterator {
167167
}
168168
}
169169

170-
/**
171-
* @typedef {(snapshot: Snapshot) => (Map<string, any> | Set<string> | undefined)[]} GetMapsFunction
172-
*/
170+
/** @typedef {Map<string, TODO> | Set<string> | undefined} SnapshotMap */
171+
/** @typedef {(snapshot: Snapshot) => SnapshotMap[]} GetMapsFunction */
173172

174173
class SnapshotIterable {
175174
/**
@@ -185,9 +184,9 @@ class SnapshotIterable {
185184
let state = 0;
186185
/** @type {IterableIterator<string>} */
187186
let it;
188-
/** @type {(snapshot: Snapshot) => (Map<string, any> | Set<string> | undefined)[]} */
187+
/** @type {GetMapsFunction} */
189188
let getMaps;
190-
/** @type {(Map<string, any> | Set<string> | undefined)[]} */
189+
/** @type {SnapshotMap[]} */
191190
let maps;
192191
/** @type {Snapshot} */
193192
let snapshot;
@@ -1336,7 +1335,7 @@ class FileSystemInfo {
13361335
* @private
13371336
* @param {string} path path
13381337
* @param {string} reason reason
1339-
* @param {any[]} args arguments
1338+
* @param {EXPECTED_ANY[]} args arguments
13401339
*/
13411340
_log(path, reason, ...args) {
13421341
const key = path + reason;

lib/FlagDependencyUsagePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class FlagDependencyUsagePlugin {
5656
/** @type {Map<ExportsInfo, Module>} */
5757
const exportInfoToModuleMap = new Map();
5858

59-
/** @type {TupleQueue<[Module, RuntimeSpec]>} */
59+
/** @type {TupleQueue<Module, RuntimeSpec>} */
6060
const queue = new TupleQueue();
6161

6262
/**

lib/Generator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
3333
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
3434
* @property {string} type which kind of code should be generated
35-
* @property {() => Map<string, any>=} getData get access to the code generation data
35+
* @property {() => Map<string, TODO>=} getData get access to the code generation data
3636
*/
3737

3838
/**

lib/HotModuleReplacementPlugin.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ class HotModuleReplacementPlugin {
9696
return hooks;
9797
}
9898

99-
/**
100-
* @param {object=} options options
101-
*/
102-
constructor(options) {
103-
this.options = options || {};
104-
}
105-
10699
/**
107100
* Apply the plugin
108101
* @param {Compiler} compiler the compiler instance

lib/Module.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const makeSerializable = require("./util/makeSerializable");
4545
/** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
4646
/** @template T @typedef {import("./util/SortableSet")<T>} SortableSet<T> */
4747
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
48+
/** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
4849
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
4950

5051
/**
@@ -93,7 +94,7 @@ const makeSerializable = require("./util/makeSerializable");
9394
/**
9495
* @typedef {object} LibIdentOptions
9596
* @property {string} context absolute context path to which lib ident is relative to
96-
* @property {object=} associatedObjectForCache object for caching
97+
* @property {AssociatedObjectForCache=} associatedObjectForCache object for caching
9798
*/
9899

99100
/**
@@ -1125,8 +1126,11 @@ class Module extends DependenciesBlock {
11251126
makeSerializable(Module, "webpack/lib/Module");
11261127

11271128
// TODO remove in webpack 6
1128-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919
11291129
Object.defineProperty(Module.prototype, "hasEqualsChunks", {
1130+
/**
1131+
* @deprecated
1132+
* @returns {EXPECTED_ANY} throw an error
1133+
*/
11301134
get() {
11311135
throw new Error(
11321136
"Module.hasEqualsChunks was renamed (use hasEqualChunks instead)"
@@ -1135,8 +1139,11 @@ Object.defineProperty(Module.prototype, "hasEqualsChunks", {
11351139
});
11361140

11371141
// TODO remove in webpack 6
1138-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919
11391142
Object.defineProperty(Module.prototype, "isUsed", {
1143+
/**
1144+
* @deprecated
1145+
* @returns {EXPECTED_ANY} throw an error
1146+
*/
11401147
get() {
11411148
throw new Error(
11421149
"Module.isUsed was renamed (use getUsedName, isExportUsed or isModuleUsed instead)"
@@ -1146,10 +1153,14 @@ Object.defineProperty(Module.prototype, "isUsed", {
11461153

11471154
// TODO remove in webpack 6
11481155
Object.defineProperty(Module.prototype, "errors", {
1156+
/**
1157+
* @deprecated
1158+
* @returns {WebpackError[]} errors
1159+
*/
11491160
get: util.deprecate(
11501161
/**
11511162
* @this {Module}
1152-
* @returns {WebpackError[]} array
1163+
* @returns {WebpackError[]} errors
11531164
*/
11541165
function () {
11551166
if (this._errors === undefined) {
@@ -1164,10 +1175,14 @@ Object.defineProperty(Module.prototype, "errors", {
11641175

11651176
// TODO remove in webpack 6
11661177
Object.defineProperty(Module.prototype, "warnings", {
1178+
/**
1179+
* @deprecated
1180+
* @returns {WebpackError[]} warnings
1181+
*/
11671182
get: util.deprecate(
11681183
/**
11691184
* @this {Module}
1170-
* @returns {WebpackError[]} array
1185+
* @returns {WebpackError[]} warnings
11711186
*/
11721187
function () {
11731188
if (this._warnings === undefined) {
@@ -1181,13 +1196,19 @@ Object.defineProperty(Module.prototype, "warnings", {
11811196
});
11821197

11831198
// TODO remove in webpack 6
1184-
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/42919
11851199
Object.defineProperty(Module.prototype, "used", {
1200+
/**
1201+
* @deprecated
1202+
* @returns {EXPECTED_ANY} throw an error
1203+
*/
11861204
get() {
11871205
throw new Error(
11881206
"Module.used was refactored (use ModuleGraph.getUsedExports instead)"
11891207
);
11901208
},
1209+
/**
1210+
* @param {EXPECTED_ANY} value value
1211+
*/
11911212
set(value) {
11921213
throw new Error(
11931214
"Module.used was refactored (use ModuleGraph.setUsedExports instead)"

lib/ModuleFilenameHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const memoize = require("./util/memoize");
1616
/** @typedef {typeof import("./util/Hash")} Hash */
1717

1818
/** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
19-
/** @typedef {{test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
19+
/** @typedef {{ test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
2020

2121
const ModuleFilenameHelpers = module.exports;
2222

0 commit comments

Comments
 (0)