vite-plugin-vue-type-imports is a Vite plugin designed to enable the use of imported TypeScript types directly within Vue's `defineProps` and `defineEmits` macros in Single File Components (SFCs). This addresses a common limitation in Vue 3's `<script setup>` where type imports are not natively processed for runtime props validation or type inference. The plugin supports both Vue 2.7+ and Vue 3.2.24+ projects. Currently at version 0.2.5, it is still in active development, indicating an irregular release cadence focused on feature enhancements and bug fixes. Its key differentiator is simplifying type management in complex Vue components by allowing external type definitions to be used seamlessly, although it has known limitations regarding advanced TypeScript features and specific import patterns.
npm install vite-plugin-vue-type-importsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to configure the plugin in `vite.config.ts` and then use an imported type (`User`) directly in a Vue 3 `<script setup>` component's `defineProps`.
Monitor the project's GitHub repository for updates and test thoroughly. Report any encountered issues to the maintainers.
Refactor namespace imports to use named imports (e.g., `import { Foo } from 'foo'`) or import individual types explicitly.Simplify complex type definitions where possible, or define them directly within the `<script setup>` block without relying on external imports for these specific complex types.
Ensure all type imports and definitions intended for `defineProps` or `defineEmits` are placed within the `<script setup lang="ts">` block.
Avoid circular type dependencies or ensure they are explicitly defined within their own scope (e.g., `interface Foo { foo: Foo }`) without an intermediate type alias causing an infinite loop.Rename types that end with numerical suffixes to avoid potential conflicts with plugin-generated identifiers.
Change namespace imports to named imports, e.g., `import { MyType1, MyType2 } from './types'`.Simplify the problematic TypeScript type definition or define it directly within the `<script setup>` block rather than importing it.
Move the definition or import of 'MyType' from `<script>` to the `<script setup lang="ts">` block of your Vue component.