This repository has been archived by the owner on Feb 18, 2024. It is now read-only.
Fix types for Config.resolve plugins and improve Plugin types #213
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes
Config.resolve.plugin
call expecting awebpack.Plugin
type despite those plugins being passed anenhanced-resolve/lib/Resolver
argument type. (As seen in this test which uses it as a resolve plugin)webpack.Plugin
in order to stay fully backwards compatible with previous versions.Allows passing
string
toPlugin.use()
as those get required bywebpack-chain
here.Allows passing
PluginType
toPlugin.use()
andPlugin.init()
as the default implementation allows it.Adds tests for the changes.
To make that possible,
@types/enhanced-resolve
and@types/tapable
were added todevDependencies
to allow the tests to work.The
webpack.ResolvePlugin
type currently usesany
as theapply()
argument type. The tests use theResolver
type to future-proof.As it turns out the reason is that the DefinitelyTyped
enhanced-resolve
types are a major behind, so the DefinitelyTyped types forwebpack
simply don't reference them. They can't be reused either, asenhanced-resolve
v3 usestapable
v0 whileenhanced-resolve
v4 usestapable
v1. See enhanced-resolve types for v4 are missing DefinitelyTyped/DefinitelyTyped#40804Meanwhile, the official webpack types are also invalid. I created an issue on the official webpack repo to track that: Type definitions use normal webpack plugin types for resolve.plugins webpack/webpack#10073.