diff --git a/packages/@vuepress/types/index.d.ts b/packages/@vuepress/types/index.d.ts index 4b831df9e6..2574014969 100644 --- a/packages/@vuepress/types/index.d.ts +++ b/packages/@vuepress/types/index.d.ts @@ -4,10 +4,10 @@ import { PluginOptions, DefaultThemeConfig, Theme, - Plugin, -} from './src' + Plugin +} from "./src"; -export * from './src' +export * from "./src"; /** * A helper function to define VuePress config file. @@ -30,11 +30,16 @@ export function defineConfig4CustomTheme( * * @see https://vuepress.vuejs.org/theme/option-api.html */ -export function defineTheme(config: Theme): void; +export function defineTheme( + config: Theme +): void; /** * A helper function to define VuePress theme entry file. * * @see https://vuepress.vuejs.org/plugin/writing-a-plugin.html */ -export function definePlugin(config: Plugin): void; +export function definePlugin< + T extends PluginOptions = PluginOptions, + U extends ThemeConfig = ThemeConfig +>(config: Plugin): void; diff --git a/packages/@vuepress/types/src/plugin-api.ts b/packages/@vuepress/types/src/plugin-api.ts index c1f14e5ad4..c25b034caf 100644 --- a/packages/@vuepress/types/src/plugin-api.ts +++ b/packages/@vuepress/types/src/plugin-api.ts @@ -4,6 +4,8 @@ import { UserPlugins, PluginOptions } from "./plugin"; import { ChainWebpack, Hook, AsyncHook, PluginObject } from "./shared"; import { Page, Context } from "./context"; import { ExtendMarkdown } from "./markdown"; +import { ThemeConfig } from "./theme"; +import { Config } from "./config"; export type PlainObjectWithStringValue = Record; @@ -82,6 +84,7 @@ export type PluginEntryOptions = { enhanceAppFiles?: | string | string[] + | Hook<[], FileDescriptor | FileDescriptor[]> | AsyncHook<[], FileDescriptor | FileDescriptor[]>; /** * Generate some client modules at compile time. @@ -94,7 +97,9 @@ export type PluginEntryOptions = { * * @see https://vuepress.vuejs.org/plugin/option-api.html#extendpagedata */ - extendPageData?: (page: Page & T) => void; + extendPageData?: ( + page: Page & T + ) => void; /** * A path to the mixin file which allows you to control the lifecycle of root component. * @@ -161,6 +166,7 @@ export type PluginEntry = PluginEntryOptions & { * * @see https://vuepress.vuejs.org/plugin/writing-a-plugin.html */ -export type Plugin = - | PluginEntry - | ((options: T, ctx: Context) => PluginEntry); +export type Plugin< + T extends PluginOptions = PluginOptions, + U extends ThemeConfig = ThemeConfig +> = PluginEntry | ((options: T, ctx: Context>) => PluginEntry); \ No newline at end of file