Add typings for library template plugins#7251
Conversation
fe1a425 to
ed9d024
Compare
| /** @typedef {import("./Compilation")} Compilation */ | ||
|
|
||
| /** | ||
| * @param {string[]} accessor the accessor to convert to path |
|
|
||
| class ExportPropertyMainTemplatePlugin { | ||
| /** | ||
| * @param {string|string[]} property the name of the property to export |
There was a problem hiding this comment.
This class doesn't write to it so this can be string|ReadonlyArray<string> too
| */ | ||
| apply(compilation) { | ||
| const { mainTemplate, chunkTemplate } = compilation; | ||
|
|
There was a problem hiding this comment.
onRenderWithEntry is missing types (I guess you're more focused on public API for now?)
| /** @typedef {import("./Compiler")} Compiler */ | ||
|
|
||
| /** | ||
| * @param {string[]} accessor the accessor to convert to path |
| if (idx === accessor.length - 1) return a; | ||
| /** | ||
| * @param {string=} base the path prefix | ||
| * @param {string|string[]} accessor the accessor |
There was a problem hiding this comment.
This is where I'd tell you to use string|ReadonlyArray<string> too but this would break Array.isArray. I recommend adding this to a global .d.ts, which will make Array.isArray support both ReadonlyArray and regular arrays:
interface ArrayConstructor {
isArray(arg: any): arg is ReadonlyArray<any>;
}I actually sent this as a PR to TypeScript, but it was rejected on compatibility grounds.
| /** @typedef {import("./Compilation")} Compilation */ | ||
|
|
||
| /** | ||
| * @param {string[]} accessor the accessor to convert to path |
| if (idx === accessor.length - 1) return a; | ||
| /** | ||
| * @param {string=} base the path prefix | ||
| * @param {string|string[]} accessor the accessor |
There was a problem hiding this comment.
Same problem here as in LibraryTemplatePlugin
(actually, should these functions be put in a common module?)
|
For maintainers only:
|
sokra
left a comment
There was a problem hiding this comment.
I would accept this. The comments about ReadonlyArray are true, but seems like typescript still has issue with it. This can be done in a separate PR when TS issues are fixed.
|
Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon. |
|
Thank |
What kind of change does this PR introduce?
typings
Did you add tests for your changes?
no
If relevant, link to documentation update:
n/a
Summary
Add typings for library template plugins
Does this PR introduce a breaking change?
no