Skip to content

Commit dad8876

Browse files
refactor(types): type the type arguments inferred as any
1 parent 7b01e67 commit dad8876

28 files changed

Lines changed: 88 additions & 39 deletions

‎lib/Compilation.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,6 +3184,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
31843184
const buildInfo = module.buildInfo;
31853185
if (buildInfo) {
31863186
// create a new entry
3187+
/** @type {MemCache} */
31873188
const memCache = new WeakTupleMap();
31883189
moduleMemCacheCache.set(module, {
31893190
buildInfo,

‎lib/MultiCompiler.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ module.exports = class MultiCompiler {
756756
}
757757
this.running = true;
758758

759+
/** @type {Watching[]} */
759760
const watchings = this._runGraph(
760761
(compiler, idx, callback, isBlocked, setChanged, setInvalid) => {
761762
const watching = compiler.watch(
@@ -767,7 +768,8 @@ module.exports = class MultiCompiler {
767768
watching._onChange = setChanged;
768769
watching._isBlocked = isBlocked;
769770
}
770-
return watching;
771+
// A child already running has none, and reported the error to `handler`.
772+
return /** @type {Watching} */ (watching);
771773
},
772774
(compiler, /** @type {Watching} */ watching, _callback) => {
773775
if (compiler.watching !== watching) return;

‎lib/cache/CacheFacade.js‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,12 @@ class MultiItemCache {
7373
* @returns {Promise<T | undefined>} promise with the data
7474
*/
7575
const next = (i) =>
76-
this._items[i].getPromise().then((/** @type {T} */ result) => {
77-
if (result !== undefined) return result;
78-
if (++i < this._items.length) return next(i);
79-
});
76+
/** @type {Promise<T | undefined>} */ (this._items[i].getPromise()).then(
77+
(result) => {
78+
if (result !== undefined) return result;
79+
if (++i < this._items.length) return next(i);
80+
}
81+
);
8082
return /** @type {Promise<T>} */ (next(0));
8183
}
8284

‎lib/config/cli.js‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,10 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
555555
if (isArray) {
556556
if (value === undefined) {
557557
value = {};
558-
current[name] = [...Array.from({ length: index }), value];
558+
current[name] = [
559+
.../** @type {undefined[]} */ (Array.from({ length: index })),
560+
value
561+
];
559562
cliAddedItems.set(current[name], index + 1);
560563
} else if (!Array.isArray(value)) {
561564
return {
@@ -613,15 +616,18 @@ const getObjectAndProperty = (config, schemaPath, index = 0) => {
613616
const value = current[name];
614617
if (value === undefined) {
615618
/** @type {ConfigurationValue[]} */
616-
const array = [...Array.from({ length: index }), undefined];
619+
const array = [
620+
.../** @type {undefined[]} */ (Array.from({ length: index })),
621+
undefined
622+
];
617623
current[name] = array;
618624
cliAddedItems.set(array, index + 1);
619625
return { object: array, property: index, value: undefined };
620626
} else if (!Array.isArray(value)) {
621627
/** @type {ConfigurationValue[]} */
622628
const array = [
623629
/** @type {ConfigurationValue} */ (value),
624-
...Array.from({ length: index }),
630+
.../** @type {undefined[]} */ (Array.from({ length: index })),
625631
undefined
626632
];
627633
current[name] = array;

‎lib/css/syntax-parser.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9527,6 +9527,7 @@ const _evaluateCalcProduct = (tokens, cursor) => {
95279527
if (token.type === "/") {
95289528
const divisor = right.get("");
95299529
if (divisor === undefined || right.size !== 1) return null;
9530+
/** @type {Map<string, number>} */
95309531
const out = new Map();
95319532
for (const [key, coefficient] of sum) {
95329533
const quotient = foldDivide(coefficient, divisor);
@@ -9543,6 +9544,7 @@ const _evaluateCalcProduct = (tokens, cursor) => {
95439544
const factor = rightNumber !== undefined ? rightNumber : leftNumber;
95449545
const other = rightNumber !== undefined ? sum : right;
95459546
if (factor === undefined) return null;
9547+
/** @type {Map<string, number>} */
95469548
const out = new Map();
95479549
for (const [key, coefficient] of other) {
95489550
const product = foldMultiply(coefficient, factor);
@@ -10093,6 +10095,7 @@ const _neededPrefixes = (table, name) => {
1009310095
/** @type {Set<string> | null} */
1009410096
let result = null;
1009510097
if (prefixes !== undefined) {
10098+
/** @type {Set<string>} */
1009610099
const needed = new Set();
1009710100
const prefixWindows = getPrefixWindows();
1009810101
for (const [prefix, windows] of prefixes) {
@@ -16444,6 +16447,7 @@ const _propertiesOverlap = (a, b) => {
1644416447
* @returns {Set<string>} the property names, lowercased
1644516448
*/
1644616449
const _blockProperties = (body) => {
16450+
/** @type {Set<string>} */
1644716451
const out = new Set();
1644816452
let depth = 0;
1644916453
let quote = 0;

‎lib/dependencies/helpers/processExportInfo.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const processExportInfo = (
4949
return;
5050
}
5151
// Only the recursive path needs the visited set; allocate it lazily
52+
/** @type {Set<InstanceType<ExportInfo>>} */
5253
const visited = alreadyVisited !== undefined ? alreadyVisited : new Set();
5354
visited.add(exportInfo);
5455
const exportsInfo = exportInfo.exportsInfo;

‎lib/fs/FileSystemInfo.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ const INVALID = Symbol("invalid");
173173
* @property {boolean=} timestamp should use timestamp to snapshot
174174
*/
175175

176-
const DONE_ITERATOR_RESULT = new Set().keys().next();
176+
const DONE_ITERATOR_RESULT = /** @type {Set<never>} */ (new Set())
177+
.keys()
178+
.next();
177179

178180
// cspell:word tshs
179181
// Tsh = Timestamp + Hash
@@ -1381,20 +1383,23 @@ class FileSystemInfo {
13811383
(s, v) => s.setManagedItemInfo(v),
13821384
false
13831385
);
1386+
/** @type {SnapshotOptimization<string, true>} */
13841387
this._managedFilesOptimization = new SnapshotOptimization(
13851388
(s) => s.hasManagedFiles(),
13861389
(s) => s.managedFiles,
13871390
(s, v) => s.setManagedFiles(v),
13881391
false,
13891392
true
13901393
);
1394+
/** @type {SnapshotOptimization<string, true>} */
13911395
this._managedContextsOptimization = new SnapshotOptimization(
13921396
(s) => s.hasManagedContexts(),
13931397
(s) => s.managedContexts,
13941398
(s, v) => s.setManagedContexts(v),
13951399
false,
13961400
true
13971401
);
1402+
/** @type {SnapshotOptimization<string, true>} */
13981403
this._managedMissingOptimization = new SnapshotOptimization(
13991404
(s) => s.hasManagedMissing(),
14001405
(s) => s.managedMissing,

‎lib/graph/buildChunkGraph.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ const visitModules = (
385385
stateEtag,
386386
() => {
387387
logger.time("visitModules: prepare");
388+
/** @type {BlockModulesMap} */
388389
const map = new Map();
389390
const source = firstBlockModulesMapByModule.get(module);
390391
if (source !== undefined) {

‎lib/html/HtmlGenerator.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class HtmlGenerator extends Generator {
604604
const crypto = require("crypto");
605605

606606
// Report each bad hash algorithm once, not once per referencing tag.
607+
/** @type {Set<string>} */
607608
const reportedBadAlgorithms = new Set();
608609

609610
const chunksById = getChunksById(compilation);

‎lib/html/HtmlModulesPlugin.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,7 @@ class HtmlModulesPlugin {
16241624
// long watch session can't accumulate stale entries.
16251625
compilation.hooks.afterSeal.tap(PLUGIN_NAME, () => {
16261626
if (sentinelResolvedSourceCache.size === 0) return;
1627+
/** @type {Set<string>} */
16271628
const live = new Set();
16281629
for (const chunk of compilation.chunks) {
16291630
live.add(String(chunk.id));

0 commit comments

Comments
 (0)