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:
Quick Start
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:
defineConfig
defineConfig4CustomTheme
defineTheme
definePlugin
Note that using @vuepress/types is equivalent to using vuepress/config.
Plugin Type
If you already have some VuePress plugins written in JS, you can leverage your IDE's intellisense with jsdoc type hints:
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.
1.9.1 (from changelog)
Bug Fixes
types: support plain string usage for known third-party plugins (dd6e3ef) @chenhaoli
import{defineConfig}from"vuepress/config";exportdefaultdefineConfig({themeConfig: {repo: "vuejs/vuepress",editLinks: true,docsDir: "packages/docs/docs"// Type is `DefaultThemeConfig`}});
If you use a custom theme, you can use the defineConfig4CustomTheme helper with ability to pass generic type for your theme:
import{defineConfig4CustomTheme}from"vuepress/config";interfaceMyThemeConfig{hello: string;}exportdefaultdefineConfig4CustomTheme<MyThemeConfig>({themeConfig: {// Type is `MyThemeConfig`hello: "vuepress"}});
Type Inferences for Official Plugins
From now, you’ll be able to enjoy the type prompt of the official plugins:
VuePress’s configuration can also be a function, while its first parameter is the current app context:
import{defineConfig}from"vuepress/config";exportdefaultdefineConfig(ctx=>({// do not execute babel compilation under developmentevergreen: ctx.isProd}));
Limitations
It is worth noting that third-party plugins do not support Plugin Shorthand if you’re using Tuple Style to write your config, this is because from the perspective of the type system, the unknown shortcut is equivalent to string, which results in the failure of type inference.
By default, only officially maintained and plugins under VuePress Community support shortcut, feel free to submit pull request to add your plugin at this file.
Credits
bundle-require (by @egoist): we leverage it under the hood to resolve user's config, which is powered by esbuild.
vscode-ts-in-markdown (by @Amour1688): this documentation is powered by this plugin, which makes type checking possible in markdown.
Depfu will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with @depfu rebase.
All Depfu comment commands
@depfu rebase
Rebases against your default branch and redoes this update
@depfu recreate
Recreates this PR, overwriting any edits that you've made to it
@depfu merge
Merges this PR once your tests are passing and conflicts are resolved
@depfu close
Closes this PR and deletes the branch
@depfu reopen
Restores the branch and reopens this PR (if it's closed)
@depfu pause
Ignores all future updates for this dependency and closes this PR
@depfu pause [minor|major]
Ignores all future minor/major updates for this dependency and closes this PR
@depfu resume
Future versions of this dependency will create PRs again (leaves this PR as is)
Here is everything you need to know about this update. Please take a good look at what changed and the test results before merging this pull request.
What changed?
✳️ vuepress (1.8.3 → 1.9.4) · Repo · Changelog
Release Notes
1.9.4 (from changelog)
1.9.3 (from changelog)
1.9.2
1.9.1 (from changelog)
1.9.0
Does any of this look wrong? Please let us know.
Commits
See the full diff on Github. The new version differs by 40 commits:
build: release version 1.9.4
feat(types): expose all plugin types
fix(types): add missing default theme config `activeHeaderLinks`
chore(types): tsconfig.json
ci(types): lint types under development
fix(types): '_filePath' implicitly has an 'any' type
fix(types): cannot find module '../../shared-utils/src/datatypes'
chore(theme-default): type comment
docs: add guide to deploy site to Layer0 (#2972)
chore(all): 1.9.3 changelog
build: release version 1.9.3
fix(types): all plugin option api should be optional
chore: tweaks
chore: changelog for 1.9.2
chore(all): 1.9.2 changelog
build: release version 1.9.2
fix(types): regression issue of reusing define helpers
chore: fix outdated links
refactor: typed all official plugins
feat(types): `definePluginEntry` helper to infer type for plugin entry
refactor(types): move helpers to `@vuepress/types`
feat(types): `defineThemeEntry` helper to infer type for theme entry
chore(types): tweaks
chore: clean outdated changelog
feat(types): init `@vuepress/types`
chore: clean outdated links
chore(all): 1.9.1 changelog
build: release version 1.9.1
fix(types): support plain string usage for known third-party plugins
ci: allow scope `types` for commit
chore: changelog image
chore: changelog
chore(all): 1.9.0 changelog
build: release version 1.9.0
docs: fix textlint
feat: typescript support for config file (#2973)
chore: add vscode settings
chore: add `amour1688.ts-in-markdown` as recommended vscode extension
ci: tweak commit lint scope
chore: 1.8.3 changelog
Depfu will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with
@depfu rebase
.All Depfu comment commands