fix(v2): fix bad @docusaurus/types Plugin type generics (#5058)

* 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>
This commit is contained in:
Jules Sam. Randolph 2021-06-25 10:18:13 -03:00 committed by GitHub
parent 67d31f49e8
commit 0ae8a09ba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View file

@ -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"
}
}

View file

@ -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> & {
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>;

View file

@ -0,0 +1,7 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"extends": "../../tsconfig.json",
"compilerOptions": {
"noEmit": true
}
}

View file

@ -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"