chore: fixed type issues in _createLoaderContext#19233
Merged
alexander-akait merged 1 commit intowebpack:mainfrom Feb 27, 2025
Merged
chore: fixed type issues in _createLoaderContext#19233alexander-akait merged 1 commit intowebpack:mainfrom
_createLoaderContext#19233alexander-akait merged 1 commit intowebpack:mainfrom
Conversation
Andarist
commented
Feb 15, 2025
lib/NormalModule.js
Outdated
| const loaderContext = { | ||
| version: 2, | ||
| /** | ||
| * @param {import("../declarations/LoaderContext").Schema} [schema] |
Contributor
Author
There was a problem hiding this comment.
the main purpose of this annotation is to make schema parameter optional, so this function can be correctly matched against both getOptions overloads
Andarist
commented
Feb 15, 2025
| child.resolve({}, context, request, getResolveContext(), callback); | ||
| } else { | ||
| return new Promise((resolve, reject) => { | ||
| return /** @type {ReturnType<import("../declarations/LoaderContext").NormalModuleLoaderContext<T>["getResolve"]>} */ ( |
Contributor
Author
There was a problem hiding this comment.
This introduces a cast, which I think is fine here. You can only type overloads using overloads signatures + 1 extra implementations signature. Since you want to benefit here from contextual typing... this function here is your implementation signature already and you can bring in the public overloads with a cast. It's either this or retyping everything locally here with regular~ overloads syntax or just changing the types to accommodate the upcoming change in some other way.
bac1591 to
907cd7e
Compare
alexander-akait
approved these changes
Feb 27, 2025
Member
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR makes the codebase compatible with the (probably) incoming microsoft/TypeScript#56907 . At the moment, contextually-typed functions in JS files are overly permissive - unlike their TS counterparts. See the comparison here
What kind of change does this PR introduce?
internal types fix
Did you add tests for your changes?
No
Does this PR introduce a breaking change?
No
What needs to be documented once your changes are merged?
Nothing