Skip to content

Commit

Permalink
fix(v2): fix bad @docusaurus/types Plugin type generics (#5058)
Browse files Browse the repository at this point in the history
* fix(types): type `LoadedPlugin` is not generic

`LoadedPlugin` referenced line 201 is not generic, causing typescript errors on
end-user builds.

* chore(types): add typescript dev dep, tsconfig and a test script

Contributors will no longer inadvertently dump type errors since any IDE should
check types now.

* add missing plugins generic types

Co-authored-by: slorber <lorber.sebastien@gmail.com>
  • Loading branch information
jsamr and slorber authored Jun 25, 2021
1 parent 67d31f4 commit 0ae8a09
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/docusaurus-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@
"directory": "packages/docusaurus-types"
},
"license": "MIT",
"scripts": {
"test": "tsc -p ."
},
"dependencies": {
"commander": "^5.1.0",
"joi": "^17.4.0",
"querystring": "0.2.0",
"webpack": "^5.40.0",
"webpack-merge": "^5.8.0"
},
"devDependencies": {
"typescript": "^4.3.4"
}
}
10 changes: 6 additions & 4 deletions packages/docusaurus-types/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export interface Props extends LoadContext, InjectedHtmlTags {
siteMetadata: DocusaurusSiteMetadata;
routes: RouteConfig[];
routesPaths: string[];
plugins: LoadedPlugin<unknown>[];
plugins: LoadedPlugin[];
}

export interface PluginContentLoadedActions {
Expand All @@ -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?({
Expand Down Expand Up @@ -283,12 +283,14 @@ export interface Plugin<Content> {
}): ThemeConfig;
}

export type InitializedPlugin = Plugin<unknown> & {
export type InitializedPlugin<Content = unknown> = Plugin<Content> & {
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>;
Expand Down
7 changes: 7 additions & 0 deletions packages/docusaurus-types/tsconfig.json
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
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18490,6 +18490,11 @@ typescript@^4.1.5:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.2.tgz#399ab18aac45802d6f2498de5054fcbbe716a805"
integrity sha512-zZ4hShnmnoVnAHpVHWpTcxdv7dWP60S2FsydQLV8V5PbS3FifjWFFRiHSWpDJahly88PRyV5teTSLoq4eG7mKw==

typescript@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.3.4.tgz#3f85b986945bcf31071decdd96cf8bfa65f9dcbc"
integrity sha512-uauPG7XZn9F/mo+7MrsRjyvbxFpzemRjKEZXS4AK83oP2KKOJPvb+9cO/gmnv8arWZvhnjVOXz7B49m1l0e9Ew==

ua-parser-js@^0.7.18:
version "0.7.28"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.28.tgz#8ba04e653f35ce210239c64661685bf9121dec31"
Expand Down

0 comments on commit 0ae8a09

Please sign in to comment.