Skip to content

Commit 297d6f3

Browse files
authored
Add instructions for type-only imports
Because Vue uses isolatedModules, it is necessary to used type-only import syntax when importing types. Discovering the resolution for this edge case is difficult when first beginning to work with TypeScript and Vue/Vite.
1 parent ca5f159 commit 297d6f3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/guide/typescript/overview.md

+15
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ let x: string | number = 1
208208
If using Vue CLI or a webpack-based setup, TypeScript in template expressions requires `vue-loader@^16.8.0`.
209209
:::
210210

211+
### Importing Types
212+
Because [`compilerOptions.isolatedModules`](https://www.typescriptlang.org/tsconfig#isolatedModules) is set to `true` (due to Vite using [esbuild](https://esbuild.github.io/) for transpiling), it is necessary when using [`type only imports`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html) to use the `import type` syntax.
213+
214+
In other words, when importing a type you would typically use:
215+
216+
```vue
217+
import { Product } from 'product.interface
218+
```
219+
220+
Instead, you should use:
221+
222+
```vue
223+
import type { Product } from 'product.interface
224+
```
225+
211226
### Usage with TSX
212227

213228
Vue also supports authoring components with JSX / TSX. Details are covered in the [Render Function & JSX](/guide/extras/render-function.html#jsx-tsx) guide.

0 commit comments

Comments
 (0)