changelog/1.9.2.md
We've announced VuePress 1.9 that takes full TypeScript Support for Config File, while VuePress 1.9.2 ships with TS Support for VuePress Plugin and Theme:
<p align="center"> </img> <p>In order to make the plugin developer not dependent on VuePress for development, we provide a completely independent type package @vuepress/types:
npm i @vuepress/types -D
@vuepress/types exports four functions:
defineConfigdefineConfig4CustomThemedefineThemedefinePluginNote that using @vuepress/types is equivalent to using vuepress/config.
If you already have some VuePress plugins written in JS, you can leverage your IDE's intellisense with jsdoc type hints:
/**
* @type {import('@vuepress/types').Plugin}
*/
module.exports = {
ready() {
// ...
}
};
Alternatively, you can use the defineConfig helper which should provide intellisense without the need for jsdoc annotations:
import { definePlugin } from "@vuepress/types";
export default definePlugin({
// ...
});
Type of plugin options also supports passing in through generic type:
import { definePlugin } from "@vuepress/types";
interface Options {
name: string;
}
export default definePlugin<Options>((options, ctx) => {
return {
ready() {
return ctx.base + options.name;
}
};
});
Similar to plugin, the only difference is the type you use, and the define function:
/**
- * @type {import('@vuepress/types').Plugin}
+ * @type {import('@vuepress/types').Theme}
*/
-import { definePlugin } from "@vuepress/types";
+import { defineTheme } from "@vuepress/types";
-export default definePlugin({
+export default defineTheme({
// ...
});
Type of theme config also supports passing in through generic type:
import { defineTheme } from "@vuepress/types";
interface ThemeConfig {
lang: string;
}
export default defineTheme<ThemeConfig>((themeConfig, ctx) => {
return {
ready() {
return ctx.base + themeConfig.lang;
}
};
});
It is worth noting that, unlike the site configuration, i.e. .vuepress/config.js, if you use TypeScript to write theme or plugin, you still need to compile it into JavaScript before publishing it to NPM.