Skip to content

Commit ca71122

Browse files
committed
docs: adapt example about adding global types
Close #353
1 parent bd7d5b1 commit ca71122

File tree

1 file changed

+32
-8
lines changed

1 file changed

+32
-8
lines changed

docs/introduction.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,20 @@ build({
7676

7777
## Setup
7878

79-
After adding this plugin, **start the dev server** (usually `npm run dev`) **to generate the first version of the types** at `typed-router.d.ts` which should be added to your `tsconfig.json` along with `unplugin-vue-router/client` to `types` and `"moduleResolution": "Bundler"`. This is what it should look like:
79+
After adding this plugin, **start the dev server** (usually `npm run dev`) **to generate the first version of the types** at `typed-router.d.ts` which should be added to your `tsconfig.json` along with `"moduleResolution": "Bundler"`. This is what it should look like:
8080

8181
::: code-group
8282

83-
```json{4,8,11} [tsconfig.json]
83+
```json{8} [tsconfig.json]
8484
{
8585
"include": [
8686
// other files...
87-
"./typed-router.d.ts"
87+
"./typed-router.d.ts" // [!code ++]
8888
],
8989
"compilerOptions": {
9090
// ...
9191
"moduleResolution": "Bundler",
92-
"types": [
93-
// other types...
94-
"unplugin-vue-router/client"
95-
]
96-
// other options...
92+
// ...
9793
}
9894
}
9995
```
@@ -128,6 +124,34 @@ declare module 'vue-router/auto-routes' {
128124

129125
:::
130126

127+
Then, if you have an `env.d.ts` file like the one created by `npm vue create <my-project>`, add the `unplugin-vue-router/client` types to it:
128+
129+
::: code-group
130+
131+
```ts [env.d.ts]
132+
/// <reference types="vite/client" />
133+
/// <reference types="unplugin-vue-router/client" /> // [!code ++]
134+
```
135+
136+
:::
137+
138+
If you don't have an `env.d.ts` file, you can create one and add the unplugin-vue-router types to it _or_ you can add them to the `types` property in your `tsconfig.json`:
139+
140+
::: code-group
141+
142+
```json [tsconfig.json]
143+
{
144+
"compilerOptions": {
145+
// ...
146+
"types": [
147+
"unplugin-vue-router/client" // [!code ++]
148+
]
149+
}
150+
}
151+
```
152+
153+
:::
154+
131155
Instead of importing from `vue-router`, you should import from `vue-router/auto`.
132156

133157
::: tip

0 commit comments

Comments
 (0)