Skip to content

Commit 71bed58

Browse files
authored
docs: add types for theme config (#3117)
* docs: add types for theme config * chore: missing {}
1 parent 6cf1de5 commit 71bed58

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/guide/extending-default-theme.md

+18
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export default {
9898
// .vitepress/theme/index.js
9999
import DefaultTheme from 'vitepress/theme'
100100

101+
/** @type {import('vitepress').Theme} */
101102
export default {
102103
extends: DefaultTheme,
103104
enhanceApp(ctx) {
@@ -107,6 +108,23 @@ export default {
107108
}
108109
```
109110

111+
If you're using TypeScript:
112+
```ts
113+
// .vitepress/theme/index.ts
114+
import type { Theme } from 'vitepress'
115+
import DefaultTheme from 'vitepress/theme'
116+
117+
export default {
118+
// ...
119+
async enhanceApp({ app }) {
120+
if (!import.meta.env.SSR) {
121+
const plugin = await import('plugin-that-access-window-on-import')
122+
app.use(plugin)
123+
}
124+
}
125+
} satisfies Theme
126+
```
127+
110128
Since we are using Vite, you can also leverage Vite's [glob import feature](https://vitejs.dev/guide/features.html#glob-import) to auto register a directory of components.
111129

112130
## Layout Slots

docs/guide/ssr-compat.md

+17
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Since [`Theme.enhanceApp`](./custom-theme#theme-interface) can be async, you can
5252
5353
```js
5454
// .vitepress/theme/index.js
55+
/** @type {import('vitepress').Theme} */
5556
export default {
5657
// ...
5758
async enhanceApp({ app }) {
@@ -63,6 +64,22 @@ export default {
6364
}
6465
```
6566
67+
If you're using TypeScript:
68+
```ts
69+
// .vitepress/theme/index.ts
70+
import type { Theme } from 'vitepress'
71+
72+
export default {
73+
// ...
74+
async enhanceApp({ app }) {
75+
if (!import.meta.env.SSR) {
76+
const plugin = await import('plugin-that-access-window-on-import')
77+
app.use(plugin)
78+
}
79+
}
80+
} satisfies Theme
81+
```
82+
6683
### `defineClientComponent`
6784
6885
VitePress provides a convenience helper for importing Vue components that access browser APIs on import.

0 commit comments

Comments
 (0)