Skip to content

Conversation

@Andarist
Copy link
Contributor

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

const loaderContext = {
version: 2,
/**
* @param {import("../declarations/LoaderContext").Schema} [schema]
Copy link
Contributor Author

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"]>} */ (
Copy link
Contributor Author

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.

@Andarist Andarist force-pushed the fix/contextual-signature-compat branch from bac1591 to 907cd7e Compare February 15, 2025 08:47
@TheLarkInn TheLarkInn requested a review from Copilot February 18, 2025 19:45
Copy link

Copilot AI left a 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.

@alexander-akait alexander-akait merged commit 3ee8d5f into webpack:main Feb 27, 2025
62 of 63 checks passed
@alexander-akait
Copy link
Member

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants