feat: typescript support for config file #2973
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.


Overview
Features
Support
.vuepress/config.tsPreviously, VuePress only supported these configurations
.vuepress/config.js.vuepress/config.yml.vuepress/config.tomlFrom now on,
.vuepress/config.tsget officially supported.defineConfighelper for config intellisenseA helper function exposed at
vuepress/config, which helps you to have type prompt:Type Inferences for Theme
By default,
defineConfighelper leverages the theme config type from default theme:If you use a custom theme, you can use the
defineConfig4CustomThemehelper with ability to pass generic type for your theme:Type Inferences for Official Plugins
From now, you’ll be able to enjoy the type prompt of the official plugins:
Options of the official plugins certainly have type prompts, Both Tuple Style and Object Style, and Plugin Shorthand support type inference:
The illustration snapshot is omitted here, you can try it yourself.
ISO Language Code
Type inference supports ISO Language Code
Context API
VuePress's configuration can also be a function, while its first parameter is the current app context:
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
esbuild.