-
-
Notifications
You must be signed in to change notification settings - Fork 8.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
fix(v2): fix bad @docusaurus/types Plugin type generics #5058
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ export interface Props extends LoadContext, InjectedHtmlTags { | |
siteMetadata: DocusaurusSiteMetadata; | ||
routes: RouteConfig[]; | ||
routesPaths: string[]; | ||
plugins: LoadedPlugin<unknown>[]; | ||
plugins: LoadedPlugin[]; | ||
} | ||
|
||
export interface PluginContentLoadedActions { | ||
|
@@ -219,7 +219,7 @@ export type AllContent = Record< | |
// TODO improve type (not exposed by postcss-loader) | ||
export type PostCssOptions = Record<string, unknown> & {plugins: unknown[]}; | ||
|
||
export interface Plugin<Content> { | ||
export interface Plugin<Content = unknown> { | ||
name: string; | ||
loadContent?(): Promise<Content>; | ||
contentLoaded?({ | ||
|
@@ -283,12 +283,14 @@ export interface Plugin<Content> { | |
}): ThemeConfig; | ||
} | ||
|
||
export type InitializedPlugin = Plugin<unknown> & { | ||
export type InitializedPlugin<Content = unknown> = Plugin<Content> & { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also adding the missing plugin content generic to these derived types |
||
readonly options: PluginOptions; | ||
readonly version: DocusaurusPluginVersionInformation; | ||
}; | ||
|
||
export type LoadedPlugin = InitializedPlugin & {readonly content: unknown}; | ||
export type LoadedPlugin<Content = unknown> = InitializedPlugin<Content> & { | ||
readonly content: Content; | ||
}; | ||
|
||
export type PluginModule = { | ||
<T, X>(context: LoadContext, options: T): Plugin<X>; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/tsconfig", | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true | ||
} | ||
} |
This file contains 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
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.
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.
Is this supposed to catch the error? Because I tried locally and it doesn't.
Actually trying to find a solution to catch such mistakes 🤪 let me know if you find one
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.
Oh I see what happened. I tested a custom
tsconfig.json
file, then I realized there was a shared config and usedextends
. But the TS server didn't reboot and kept the former config, thus I thought the new config would still catch those errors.And the new config brought
"skipLibCheck": true
which caused declaration files to be ignored. But if I revert that, all those@types/webpack
error spawn.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.
Those webpack errors come from conflicting
tapable
definitions.@types/[email protected]
depends on@types/tapable@^1" while
[email protected]depends on
tapable@^2` which provides its own definitions.Not sure what is meant by "@types/webpack and webpack/types.d.ts are not the same thing" 😓 (in root tsconfig); but either upgrading @types/webpack to ^5 or sticking with TS types provided by webpack might fix the issue...
Those TS errors in node_modules are maddening!
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.
Previously Webpack used definitively typed (4.x); but it started to ship official typedefs in 5.x. The initial 5.x typedefs were missing a lot of things, I think they completed support more recently so we can probably try again to remove
@types/webpack
once for all