mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-29 22:47:52 +02:00
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:
parent
67d31f49e8
commit
0ae8a09ba5
4 changed files with 24 additions and 4 deletions
|
@ -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
packages/docusaurus-types/src/index.d.ts
vendored
10
packages/docusaurus-types/src/index.d.ts
vendored
|
@ -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>;
|
||||
|
|
7
packages/docusaurus-types/tsconfig.json
Normal file
7
packages/docusaurus-types/tsconfig.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"$schema": "http://json.schemastore.org/tsconfig",
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue