fix: types for errors and warnings#20880
Conversation
🦋 Changeset detectedLatest commit: a299537 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (a299537). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@a299537
yarn add -D webpack@https://pkg.pr.new/webpack@a299537
pnpm add -D webpack@https://pkg.pr.new/webpack@a299537 |
There was a problem hiding this comment.
Pull request overview
Updates webpack’s JSdoc/TypeScript surface types around errors and warnings, and extracts NonErrorEmittedError into its own module.
Changes:
- Align module error/warning APIs and related callbacks to use
Errortypes (JSdoc +types.d.ts). - Extract
NonErrorEmittedErrorintolib/errors/NonErrorEmittedError.jsand updateNormalModuleto use it. - Adjust a plugin import path in
WebpackOptionsApplyand add a changeset entry.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| types.d.ts | Updates generated TS declarations for module/cache error & warning typing. |
| lib/errors/NonErrorEmittedError.js | New extracted error class with serialization registration. |
| lib/errors/HookWebpackError.js | Updates callback typing in JSdoc to Error | null. |
| lib/WebpackOptionsApply.js | Changes RequireJsStuffPlugin require path used when AMD is enabled. |
| lib/Watching.js | Updates error typing in JSdoc and removes unused typedef. |
| lib/NormalModule.js | Switches to the extracted NonErrorEmittedError and updates error typing annotations. |
| lib/Module.js | Broadens warnings/errors storage and APIs to Error[] in JSdoc. |
| lib/Compilation.js | Adjusts typing around module.getErrors()/getWarnings() usage via casts. |
| lib/Cache.js | Updates cache callback JSdoc error typing and description. |
| .changeset/violet-news-add.md | Declares a patch release for the typing fix. |
Comments suppressed due to low confidence (1)
lib/Compilation.js:3222
module.getErrors()/getWarnings()are now typed to returnError[], but these are cast toWebpackError[]here. If any callers add plainErrorobjects to a module, this cast is incorrect/misleading; consider using a narrower intersection type for the.moduleassignment (e.g.Error & { module?: Module }) or updating the upstream types sogetErrors()isWebpackError[]if that’s the real invariant.
const errors = /** @type {WebpackError[]} */ (module.getErrors());
if (errors !== undefined) {
for (const error of errors) {
if (!error.module) {
error.module = module;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (84.61%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #20880 +/- ##
==========================================
+ Coverage 83.18% 89.05% +5.87%
==========================================
Files 530 555 +25
Lines 53878 55027 +1149
Branches 14218 14471 +253
==========================================
+ Hits 44816 49007 +4191
+ Misses 9062 6020 -3042
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 40.38%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "devtool-eval-source-map", scenario '{"name":"mode-development","mode":"development"}' |
1.1 MB | 1.4 MB | -22.51% |
| ⚡ | Memory | benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' |
9.6 MB | 7.6 MB | +26.89% |
| ⚡ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
979.9 KB | 455 KB | ×2.2 |
| ❌ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-development","mode":"development"}' |
852.4 KB | 1,142.4 KB | -25.38% |
| ❌ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
999 KB | 1,377.8 KB | -27.49% |
| ❌ | Memory | benchmark "concatenate-modules", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
183.4 KB | 307.6 KB | -40.38% |
| ❌ | Memory | benchmark "devtool-eval", scenario '{"name":"mode-development","mode":"development"}' |
734 KB | 976 KB | -24.8% |
| ⚡ | Memory | benchmark "many-modules-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
250.9 KB | 166.7 KB | +50.52% |
| ❌ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-development","mode":"development"}' |
797.9 KB | 1,304.1 KB | -38.82% |
| ⚡ | Memory | benchmark "side-effects-reexport", scenario '{"name":"mode-production","mode":"production"}' |
5.8 MB | 4.4 MB | +30.63% |
Comparing refactor-types-webpack-error (a299537) with main (d6e5881)
881dba8 to
a299537
Compare
Summary
fix types for errors and warnings
What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Existing
Does this PR introduce a breaking change?
No
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Nothing
Use of AI
No