Skip to content

Commit b8b90d6

Browse files
fix: less any types (#19382)
1 parent 05b39c2 commit b8b90d6

37 files changed

+355
-197
lines changed

eslint.config.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,12 @@ export default [
358358
"JsdocBlock:has(JsdocTag[tag!=/^(typedef|template|param)$/]:has(JsdocTypeName[value=/^(Object|object)$/]))",
359359
message:
360360
"Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`/`object` or use `EXPECTED_OBJECT` type"
361+
},
362+
{
363+
comment:
364+
"JsdocBlock:has(JsdocTag[tag=typedef][parsedType.type!=JsdocTypeName]:has(JsdocTypeName[value=/^(Object|object)$/]))",
365+
message:
366+
"Please use provide types for object - `{ property: number:, result: () => number}` instead `Object`/`object` or use `EXPECTED_OBJECT` type"
361367
}
362368
]
363369
}

lib/Compilation.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ const { isSourceEqual } = require("./util/source");
220220
* @property {EntryOptions=} entryOptions
221221
*/
222222

223-
/** @typedef {Record<string, any>} ExecuteModuleExports */
223+
/** @typedef {Record<string, EXPECTED_ANY>} ExecuteModuleExports */
224224

225225
/**
226226
* @typedef {object} ExecuteModuleResult
@@ -276,7 +276,7 @@ const { isSourceEqual } = require("./util/source");
276276
/**
277277
* @typedef {object} LogEntry
278278
* @property {string} type
279-
* @property {any[]=} args
279+
* @property {EXPECTED_ANY[]=} args
280280
* @property {number} time
281281
* @property {string[]=} trace
282282
*/
@@ -372,17 +372,17 @@ const { isSourceEqual } = require("./util/source");
372372
* @property {false | "none" | "error" | "warn" | "info" | "log" | "verbose"} logging
373373
* @property {((value: string) => boolean)[]} loggingDebug
374374
* @property {boolean} loggingTrace
375-
* @property {any} _env
375+
* @property {TODO} _env
376376
*/
377377

378-
/** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, any>} NormalizedStatsOptions */
378+
/** @typedef {KnownNormalizedStatsOptions & Omit<StatsOptions, keyof KnownNormalizedStatsOptions> & Record<string, EXPECTED_ANY>} NormalizedStatsOptions */
379379

380380
/**
381381
* @typedef {object} KnownCreateStatsOptionsContext
382382
* @property {boolean=} forToString
383383
*/
384384

385-
/** @typedef {KnownCreateStatsOptionsContext & Record<string, any>} CreateStatsOptionsContext */
385+
/** @typedef {KnownCreateStatsOptionsContext & Record<string, EXPECTED_ANY>} CreateStatsOptionsContext */
386386

387387
/** @typedef {{ module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}} CodeGenerationJob */
388388

@@ -465,7 +465,7 @@ const compareErrors = concatComparators(byModule, byLocation, byMessage);
465465
* @property {GeneratorOptions} [generatorOptions]
466466
*/
467467

468-
/** @typedef {KnownUnsafeCacheData & Record<string, any>} UnsafeCacheData */
468+
/** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
469469

470470
/**
471471
* @typedef {Module & { restoreFromUnsafeCache?: (unsafeCacheData: UnsafeCacheData, moduleFactory: ModuleFactory, compilationParams: CompilationParams) => void }} ModuleWithRestoreFromUnsafeCache
@@ -477,6 +477,8 @@ const unsafeCacheDependencies = new WeakMap();
477477
/** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
478478
const unsafeCacheData = new WeakMap();
479479

480+
/** @typedef {Map<Module, WeakTupleMap<any, any>>} ModuleMemCaches */
481+
480482
class Compilation {
481483
/**
482484
* Creates an instance of Compilation.
@@ -1047,9 +1049,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
10471049
};
10481050
defineRemovedModuleTemplates(this.moduleTemplates);
10491051

1050-
/** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
1052+
/** @type {ModuleMemCaches | undefined} */
10511053
this.moduleMemCaches = undefined;
1052-
/** @type {Map<Module, WeakTupleMap<any, any>> | undefined} */
1054+
/** @type {ModuleMemCaches | undefined} */
10531055
this.moduleMemCaches2 = undefined;
10541056
this.moduleGraph = new ModuleGraph();
10551057
/** @type {ChunkGraph} */
@@ -3096,7 +3098,12 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
30963098

30973099
const entryModules = new Set();
30983100
for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
3099-
entrypoint.addOrigin(null, { name }, /** @type {any} */ (dep).request);
3101+
entrypoint.addOrigin(
3102+
null,
3103+
{ name },
3104+
/** @type {Dependency & { request: string }} */
3105+
(dep).request
3106+
);
31003107

31013108
const module = this.moduleGraph.getModule(dep);
31023109
if (module) {
@@ -5626,7 +5633,7 @@ Object.defineProperty(compilationPrototype, "cache", {
56265633
),
56275634
set: util.deprecate(
56285635
/**
5629-
* @param {any} v value
5636+
* @param {EXPECTED_ANY} v value
56305637
*/
56315638
v => {},
56325639
"Compilation.cache was removed in favor of Compilation.getCache()",

lib/Compiler.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ const { isSourceEqual } = require("./util/source");
5353
/** @typedef {import("./util/fs").TimeInfoEntries} TimeInfoEntries */
5454
/** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
5555

56-
/**
57-
* @template {any[]} T
58-
* @template V
59-
* @typedef {import("./util/WeakTupleMap")<T, V>} WeakTupleMap
60-
*/
61-
6256
/**
6357
* @typedef {object} CompilationParams
6458
* @property {NormalModuleFactory} normalModuleFactory
@@ -97,9 +91,9 @@ const { isSourceEqual } = require("./util/source");
9791

9892
/** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
9993

100-
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
94+
/** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: CacheEntry, file: string }[] | undefined) }} SimilarEntry */
10195

102-
/** @typedef {{ buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap<any, any> }} ModuleMemCachesItem */
96+
/** @typedef {{ buildInfo: BuildInfo, references: References | undefined, memCache: import("./util/WeakTupleMap")<Module[], string> }} ModuleMemCachesItem */
10397

10498
/**
10599
* @param {string[]} array an array

lib/LoaderOptionsPlugin.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ const createSchemaValidation = require("./util/create-schema-validation");
1111

1212
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
1313
/** @typedef {import("./Compiler")} Compiler */
14+
/** @typedef {import("./ModuleFilenameHelpers").Matcher} Matcher */
1415
/** @typedef {import("./ModuleFilenameHelpers").MatchObject} MatchObject */
1516

17+
/**
18+
* @template T
19+
* @typedef {import("../declarations/LoaderContext").LoaderContext<T>} LoaderContext
20+
*/
21+
1622
const validate = createSchemaValidation(
1723
require("../schemas/plugins/LoaderOptionsPlugin.check.js"),
1824
() => require("../schemas/plugins/LoaderOptionsPlugin.json"),
@@ -31,10 +37,7 @@ class LoaderOptionsPlugin {
3137
// If no options are set then generate empty options object
3238
if (typeof options !== "object") options = {};
3339
if (!options.test) {
34-
// This is mocking a RegExp object which always returns true
35-
// TODO: Figure out how to do `as unknown as RegExp` for this line
36-
// in JSDoc equivalent
37-
/** @type {any} */
40+
/** @type {TODO} */
3841
const defaultTrueMockRegExp = {
3942
test: () => true
4043
};

lib/ModuleGraph.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ModuleGraphConnection = require("./ModuleGraphConnection");
1111
const SortableSet = require("./util/SortableSet");
1212
const WeakTupleMap = require("./util/WeakTupleMap");
1313

14+
/** @typedef {import("./Compilation").ModuleMemCaches} ModuleMemCaches */
1415
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
1516
/** @typedef {import("./Dependency")} Dependency */
1617
/** @typedef {import("./ExportsInfo").ExportInfo} ExportInfo */
@@ -124,8 +125,6 @@ class ModuleGraphModule {
124125
/** @typedef {EXPECTED_OBJECT} MetaKey */
125126
/** @typedef {TODO} Meta */
126127

127-
/** @typedef {Map<Module, WeakTupleMap<any, any>>} ModuleMemCaches */
128-
129128
class ModuleGraph {
130129
constructor() {
131130
/**

lib/MultiStats.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class MultiStats {
135135
/**
136136
* @param {StatsCompilation} j stats error
137137
* @param {StatsError} obj Stats error
138-
* @returns {TODO} result
138+
* @returns {StatsError} result
139139
*/
140140
const mapError = (j, obj) => ({
141141
...obj,

lib/NormalModule.js

+25-16
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ const memoize = require("./util/memoize");
8080
/** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
8181
/** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
8282
/** @typedef {import("./Parser")} Parser */
83+
/** @typedef {import("./Parser").PreparsedAst} PreparsedAst */
8384
/** @typedef {import("./RequestShortener")} RequestShortener */
8485
/** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
8586
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -97,8 +98,8 @@ const memoize = require("./util/memoize");
9798
* @typedef {import("./util/deprecation").FakeHook<T>} FakeHook
9899
*/
99100

100-
/** @typedef {{[k: string]: any}} ParserOptions */
101-
/** @typedef {{[k: string]: any}} GeneratorOptions */
101+
/** @typedef {{ [k: string]: EXPECTED_ANY }} ParserOptions */
102+
/** @typedef {{ [k: string]: EXPECTED_ANY }} GeneratorOptions */
102103

103104
/**
104105
* @template T
@@ -132,7 +133,7 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
132133
/**
133134
* @typedef {object} LoaderItem
134135
* @property {string} loader
135-
* @property {any} options
136+
* @property {string | null | undefined | Record<string, EXPECTED_ANY>} options
136137
* @property {string?} ident
137138
* @property {string?} type
138139
*/
@@ -208,7 +209,7 @@ const asBuffer = input => {
208209

209210
class NonErrorEmittedError extends WebpackError {
210211
/**
211-
* @param {any} error value which is not an instance of Error
212+
* @param {EXPECTED_ANY} error value which is not an instance of Error
212213
*/
213214
constructor(error) {
214215
super();
@@ -224,16 +225,16 @@ makeSerializable(
224225
"NonErrorEmittedError"
225226
);
226227

227-
/** @typedef {[string | Buffer, string | SourceMapSource, Record<string, any>]} Result */
228+
/** @typedef {[string | Buffer, string | SourceMapSource, PreparsedAst]} Result */
228229

229230
/**
230231
* @typedef {object} NormalModuleCompilationHooks
231-
* @property {SyncHook<[LoaderContext<any>, NormalModule]>} loader
232-
* @property {SyncHook<[LoaderItem[], NormalModule, LoaderContext<any>]>} beforeLoaders
232+
* @property {SyncHook<[LoaderContext<EXPECTED_ANY>, NormalModule]>} loader
233+
* @property {SyncHook<[LoaderItem[], NormalModule, LoaderContext<EXPECTED_ANY>]>} beforeLoaders
233234
* @property {SyncHook<[NormalModule]>} beforeParse
234235
* @property {SyncHook<[NormalModule]>} beforeSnapshot
235236
* @property {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} readResourceForScheme
236-
* @property {HookMap<AsyncSeriesBailHook<[LoaderContext<any>], string | Buffer | null>>} readResource
237+
* @property {HookMap<AsyncSeriesBailHook<[LoaderContext<EXPECTED_ANY>], string | Buffer | null>>} readResource
237238
* @property {SyncWaterfallHook<[Result, NormalModule]>} processResult
238239
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
239240
*/
@@ -247,7 +248,7 @@ makeSerializable(
247248
* @property {string} rawRequest request without resolving
248249
* @property {LoaderItem[]} loaders list of loaders
249250
* @property {string} resource path + query of the real resource
250-
* @property {Record<string, any>=} resourceResolveData resource resolve data
251+
* @property {TODO=} resourceResolveData resource resolve data
251252
* @property {string} context context directory for resolving
252253
* @property {string=} matchResource path + query of the matched resource (virtual)
253254
* @property {Parser} parser the parser used
@@ -260,6 +261,8 @@ makeSerializable(
260261
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
261262
const compilationHooksMap = new WeakMap();
262263

264+
/** @typedef {Map<string, EXPECTED_ANY>} CodeGeneratorData */
265+
263266
class NormalModule extends Module {
264267
/**
265268
* @param {Compilation} compilation the compilation
@@ -400,7 +403,7 @@ class NormalModule extends Module {
400403
this._isEvaluatingSideEffects = false;
401404
/** @type {WeakSet<ModuleGraph> | undefined} */
402405
this._addedSideEffectsBailout = undefined;
403-
/** @type {Map<string, any>} */
406+
/** @type {CodeGeneratorData} */
404407
this._codeGeneratorData = new Map();
405408
}
406409

@@ -694,13 +697,13 @@ class NormalModule extends Module {
694697
if (schema.title && (match = /^(.+) (.+)$/.exec(schema.title))) {
695698
[, name, baseDataPath] = match;
696699
}
697-
getValidate()(schema, options, {
700+
getValidate()(schema, /** @type {EXPECTED_OBJECT} */ (options), {
698701
name,
699702
baseDataPath
700703
});
701704
}
702705

703-
return options;
706+
return /** @type {T} */ (options);
704707
},
705708
emitWarning: warning => {
706709
if (!(warning instanceof Error)) {
@@ -811,7 +814,11 @@ class NormalModule extends Module {
811814

812815
Object.assign(loaderContext, options.loader);
813816

814-
hooks.loader.call(/** @type {LoaderContext<any>} */ (loaderContext), this);
817+
hooks.loader.call(
818+
/** @type {LoaderContext<EXPECTED_ANY>} */
819+
(loaderContext),
820+
this
821+
);
815822

816823
return loaderContext;
817824
}
@@ -915,7 +922,6 @@ class NormalModule extends Module {
915922
});
916923
return callback(error);
917924
}
918-
919925
const result = hooks.processResult.call(
920926
/** @type {Result} */ (_result),
921927
this
@@ -971,7 +977,8 @@ class NormalModule extends Module {
971977
hooks.beforeLoaders.call(
972978
this.loaders,
973979
this,
974-
/** @type {LoaderContext<any>} */ (loaderContext)
980+
/** @type {LoaderContext<EXPECTED_ANY>} */
981+
(loaderContext)
975982
);
976983
} catch (err) {
977984
processResult(/** @type {Error} */ (err));
@@ -1436,7 +1443,9 @@ class NormalModule extends Module {
14361443
runtimeRequirements.add(RuntimeGlobals.thisAsExports);
14371444
}
14381445

1439-
/** @type {() => Map<string, any>} */
1446+
/**
1447+
* @type {() => CodeGeneratorData}
1448+
*/
14401449
const getData = () => this._codeGeneratorData;
14411450

14421451
const sources = new Map();

lib/NormalModuleFactory.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const {
8484
* @property {string=} context
8585
*/
8686

87-
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
87+
/** @typedef {ResourceData & { data: Record<string, EXPECTED_ANY> }} ResourceDataWithData */
8888

8989
/**
9090
* @typedef {object} ParsedLoaderRequest

lib/Parser.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"use strict";
77

8+
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
89
/** @typedef {import("./Compilation")} Compilation */
910
/** @typedef {import("./NormalModule")} NormalModule */
1011

@@ -16,10 +17,10 @@
1617
* @property {NormalModule} current
1718
* @property {NormalModule} module
1819
* @property {Compilation} compilation
19-
* @property {{[k: string]: any}} options
20+
* @property {WebpackOptions} options
2021
*/
2122

22-
/** @typedef {Record<string, any> & ParserStateBase} ParserState */
23+
/** @typedef {Record<string, EXPECTED_ANY> & ParserStateBase} ParserState */
2324

2425
class Parser {
2526
/* istanbul ignore next */

0 commit comments

Comments
 (0)