-
-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: fixed type issues in _createLoaderContext
#19233
chore: fixed type issues in _createLoaderContext
#19233
Conversation
lib/NormalModule.js
Outdated
@@ -648,6 +648,10 @@ class NormalModule extends Module { | |||
/** @type {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} */ | |||
const loaderContext = { | |||
version: 2, | |||
/** | |||
* @param {import("../declarations/LoaderContext").Schema} [schema] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the main purpose of this annotation is to make schema
parameter optional, so this function can be correctly matched against both getOptions
overloads
child.resolve({}, context, request, getResolveContext(), callback); | ||
} else { | ||
return new Promise((resolve, reject) => { | ||
return /** @type {ReturnType<import("../declarations/LoaderContext").NormalModuleLoaderContext<T>["getResolve"]>} */ ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Thanks |
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