Skip to content

Commit 93b429e

Browse files
committed
chore(types): reduce reliance on declarations
1 parent bc3e930 commit 93b429e

236 files changed

Lines changed: 899 additions & 986 deletions

File tree

Some content is hidden

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

‎.coderabbit.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ reviews:
9393
instance field. Path-shape regexps and helpers must be imported from
9494
lib/util/identifier.js, never re-declared locally. Comments must be at
9595
most two short lines and add non-obvious information. Prefer specific
96-
types over EXPECTED_ANY/unknown when a real type fits.
96+
types over any/unknown when a real type fits.
9797
- path: "hot/**"
9898
instructions: >-
9999
Runtime code shipped to browsers; same Node >= 10.13 syntax baseline as

‎.github/scripts/publish-to-pkg-pr-new.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import fs from "fs";
55

66
/**
7-
* @param {{ github: EXPECTED_ANY, context: EXPECTED_ANY }} params params
7+
* @param {{ github: any, context: any }} params params
88
*/
99
export async function run({ github, context }) {
1010
const output = JSON.parse(fs.readFileSync("output.json", "utf8"));
@@ -43,7 +43,7 @@ pnpm add -D webpack@${output.packages.map((p) => p.url).join(" ")}
4343

4444
/**
4545
* @param {number=} issueNumber PR number
46-
* @returns {Promise<EXPECTED_ANY[]>} comments
46+
* @returns {Promise<any[]>} comments
4747
*/
4848
async function findBotComment(issueNumber) {
4949
if (!issueNumber) return null;

‎AGENTS.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ A hint reuses the reporting webpack already has rather than inventing its own: `
175175

176176
### Type annotations
177177

178-
Prefer the most specific real type. `EXPECTED_ANY`, `EXPECTED_OBJECT`, and `EXPECTED_FUNCTION` (aliases for `any`, `object`, `Function`) are an escape hatch, not a default — reach for one **only** when the value genuinely can be any value, any object, or any function, and **never** when a real type fits. `unknown` is the same: use it for a value whose type you can't yet name (then narrow it), but if a real type (e.g. an imported `import("…").Foo`) fits, use that instead. This applies in `test/` too.
178+
Prefer the most specific real type. `any`, `object`, and `Function` are an escape hatch, not a default — reach for one **only** when the value genuinely can be any value, any object, or any function, and **never** when a real type fits. `unknown` is the same: use it for a value whose type you can't yet name (then narrow it), but if a real type (e.g. an imported `import("…").Foo`) fits, use that instead. This applies in `test/` too.
179179

180-
Prefer a generic (`@template`) over a widened type whenever a function's output type depends on its input — it keeps callers precisely typed instead of collapsing to `EXPECTED_ANY`.
180+
Prefer a generic (`@template`) over a widened type whenever a function's output type depends on its input — it keeps callers precisely typed instead of collapsing to `any`.
181181

182182
### Naming
183183

@@ -302,7 +302,7 @@ Swap `ConfigTestCases` for `StatsTestCases`, `HotTestCases`, `WatchTestCases`,
302302

303303
**Cover every line you add or change.** A commit must not lower coverage: each new branch, fast path, and fallback needs a test that exercises it (CI's coverage report enforces this on the patch, target 90%+). Cover new branches with `configCases/` whenever a real build can reach them; fall back to a focused `*.unittest.js` only when a config case can't reasonably drive the branch (or a build-level test adds nothing) — e.g. tokenizer cold-path fallbacks, where each branch (fast and delegated) still needs exercising. Check `yarn cover:unit` locally, or the PR's "patch" coverage report, and add cases until no changed line is missing.
304304

305-
**Don't lower type coverage either.** webpack tracks how much of `lib/` is precisely typed; CI collects it (`yarn types:cover:report`) and reports the delta on the PR. Keep it from dropping — prefer real types over `EXPECTED_ANY` (see [Type annotations](#type-annotations)), and run `yarn types:cover` locally if you widened any annotations.
305+
**Don't lower type coverage either.** webpack tracks how much of `lib/` is precisely typed; CI collects it (`yarn types:cover:report`) and reports the delta on the PR. Keep it from dropping — prefer real types over `any` (see [Type annotations](#type-annotations)), and run `yarn types:cover` locally if you widened any annotations.
306306

307307
## Git & PR rules
308308

‎bin/webpack.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const runCli = (cli) => {
9595

9696
const pkgPath = require.resolve(`${cli.package}/package.json`);
9797

98-
/** @type {Record<string, EXPECTED_ANY> & { type: string, bin: Record<string, string> }} */
98+
/** @type {Record<string, any> & { type: string, bin: Record<string, string> }} */
9999
const pkg = require(pkgPath);
100100

101101
if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {

‎declarations.d.ts‎

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
type EXPECTED_ANY = any;
2-
type EXPECTED_FUNCTION = Function;
3-
type EXPECTED_OBJECT = object;
4-
51
declare module "*.json";
62
declare module "rimraf";
73

8-
declare module "color-name" {
9-
const colors: { [name: string]: [number, number, number] };
10-
export = colors;
11-
}
12-
13-
// Deprecated NodeJS API usages in webpack
14-
declare namespace NodeJS {
15-
interface Process {
16-
binding(internalModule: string): any;
17-
}
18-
interface ProcessVersions {
19-
pnp: "1" | "3";
20-
}
21-
}
22-
234
declare module "typescript-iterable" {
245
// New iterator interfaces from `lib.es2015.iterable.d.ts` for compatibility with old typescript versions and `dispose`
256
interface Disposable {
@@ -69,7 +50,7 @@ declare module "@webassemblyjs/ast" {
6950
export class Module extends Node {
7051
id: string;
7152
fields: Node[];
72-
metadata?: Record<string, EXPECTED_ANY>;
53+
metadata?: Record<string, any>;
7354
}
7455
export class ModuleImportDescription {
7556
type: string;
@@ -230,14 +211,3 @@ type RecursiveArrayOrRecord<T> =
230211
| { [index: string]: RecursiveArrayOrRecord<T> }
231212
| Array<RecursiveArrayOrRecord<T>>
232213
| T;
233-
234-
declare module "eslint-scope/lib/referencer" {
235-
type Property = import("estree").Property;
236-
type PropertyDefinition = import("estree").PropertyDefinition;
237-
238-
class Referencer {
239-
Property(node: PropertyDefinition | Property): void;
240-
PropertyDefinition(node: PropertyDefinition): void;
241-
}
242-
export = Referencer;
243-
}

‎declarations/WebpackOptions.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ export interface OutputHtmlOptions {
14641464
| {
14651465
[k: string]: any;
14661466
}
1467-
| ((name: string) => false | string | {[key: string]: EXPECTED_ANY});
1467+
| ((name: string) => false | string | {[key: string]: any});
14681468
/**
14691469
* Inject `<meta>` tags into the page `<head>`. Each key is the `name` attribute (or `"charset"` for a charset declaration); the value is the `content` string. Keys beginning with `og:` use the `property` attribute instead of `name`. A tag is skipped if the HTML already contains a meta with the same name.
14701470
* @since 5.109.0

‎eslint.config.mjs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export default defineConfig([
6060
rules: {
6161
// Too noise
6262
"jsdoc/require-property-description": "off",
63+
"jsdoc/reject-any-type": "off",
64+
"jsdoc/reject-function-type": "off",
6365
// Indents are used for imports
6466
"jsdoc/check-indentation": "off",
6567
// We have helpers for the default configuration
@@ -75,6 +77,9 @@ export default defineConfig([
7577
// Revisit it in future
7678
"no-use-before-define": "off",
7779

80+
// TODO: Remove this rule from special
81+
"jsdoc/no-restricted-syntax": "off",
82+
7883
// TODO We need allow to have `_arg` in tooling and use `after-used` value for `args`
7984
"no-unused-vars": [
8085
"error",

‎examples/lazy-compilation/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ document.body.appendChild(pre);
4646

4747
const { HotModuleReplacementPlugin } = require("../../");
4848

49-
/** @type {import("webpack").Configuration & { devServer: Record<string, EXPECTED_ANY> }} */
49+
/** @type {import("webpack").Configuration & { devServer: Record<string, any> }} */
5050
const config = {
5151
mode: "development",
5252
cache: {

‎examples/lazy-compilation/webpack.config.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { HotModuleReplacementPlugin } = require("../../");
44

5-
/** @type {import("webpack").Configuration & { devServer: Record<string, EXPECTED_ANY> }} */
5+
/** @type {import("webpack").Configuration & { devServer: Record<string, any> }} */
66
const config = {
77
mode: "development",
88
cache: {

‎lib/Cache.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const {
2727
* @returns {void}
2828
*/
2929

30-
/** @typedef {EXPECTED_ANY} Data */
30+
/** @typedef {any} Data */
3131

3232
/**
3333
* Handler invoked after a cache read succeeds so additional cache layers can
@@ -66,7 +66,7 @@ class Cache {
6666
*/
6767
constructor() {
6868
this.hooks = {
69-
/** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler<EXPECTED_ANY>[]], Data>} */
69+
/** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler<any>[]], Data>} */
7070
get: new AsyncSeriesBailHook(["identifier", "etag", "gotHandlers"]),
7171
/** @type {AsyncParallelHook<[string, Etag | null, Data]>} */
7272
store: new AsyncParallelHook(["identifier", "etag", "data"]),

0 commit comments

Comments
 (0)