Vite plugin that runs TypeScript type checker on a separate process.
—
Vue Single File Component type checking using vue-tsc, providing comprehensive TypeScript integration for Vue.js projects with full SFC support.
Enable and configure Vue TypeScript checking with the same flexible options as the regular TypeScript checker, specifically optimized for Vue SFC files.
/**
* Vue TypeScript checker configuration
* - Set to `true` to enable vue-tsc checking with default configuration
* - Set to `false` to disable vue-tsc checking
* - Provide partial options object for custom configuration
*/
type VueTscConfig = boolean | Partial<TsConfigOptions>;
interface TsConfigOptions {
/** Path to tsconfig.json file */
tsconfigPath: string;
/** Path to typescript package */
typescriptPath: string;
/** Root path of current working directory */
root: string;
/** Enable build mode flag */
buildMode: boolean;
}Usage Examples:
// Simple enable with defaults
checker({
vueTsc: true,
});
// Custom tsconfig for Vue
checker({
vueTsc: {
tsconfigPath: './tsconfig.vue.json',
},
});
// Full custom configuration
checker({
vueTsc: {
tsconfigPath: './tsconfig.json',
typescriptPath: require.resolve('typescript'),
root: './src',
buildMode: false,
},
});For optimal Vue TypeScript checking, your tsconfig.json should include Vue-specific settings:
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "preserve",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"types": ["vite/client"]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue"
],
"exclude": ["node_modules"]
}The Vue TypeScript checker provides comprehensive support for Vue Single File Components:
Template Type Checking:
Script Setup Support:
<script setup> blocksComposition API Integration:
When vueTsc: true is used, the following default configuration is applied:
{
tsconfigPath: 'tsconfig.json', // Look for tsconfig.json in project root
typescriptPath: 'typescript', // Use typescript from node_modules
root: process.cwd(), // Use current working directory
buildMode: false, // Enable incremental checking in dev mode
}In development mode, the Vue TypeScript checker:
In build mode, the Vue TypeScript checker:
vite build --watch mode for continuous validationProps Validation:
<script setup lang="ts">
interface Props {
message: string;
count?: number;
}
const props = withDefaults(defineProps<Props>(), {
count: 0
});
</script>
<template>
<!-- Type-checked template usage -->
<div>{{ props.message }} - {{ props.count }}</div>
</template>Emit Type Checking:
<script setup lang="ts">
interface Emits {
update: [value: string];
change: [id: number, data: object];
}
const emit = defineEmits<Emits>();
// Type-checked emit calls
emit('update', 'new value');
emit('change', 1, { data: true });
</script>Ref and Reactive Type Inference:
<script setup lang="ts">
import { ref, reactive } from 'vue';
const count = ref(0); // Ref<number>
const message = ref('hello'); // Ref<string>
const state = reactive({ // Reactive<{ items: Item[] }>
items: [] as Item[]
});
</script>Vue TypeScript errors are reported with detailed Vue-specific information:
The checker works alongside other Vue development tools:
With Vetur/Volar:
checker({
// Use vue-tsc for type checking
vueTsc: true,
// Vetur/Volar provides editor integration
});With Vue Router:
// Ensure router types are included
vueTsc: {
tsconfigPath: './tsconfig.json', // Should include vue-router types
}With Pinia:
// Type-safe store integration
vueTsc: {
tsconfigPath: './tsconfig.json', // Should include pinia types
}For large Vue projects, consider these optimizations:
// tsconfig.json
{
"compilerOptions": {
"incremental": true, // Enable incremental compilation
"skipLibCheck": true, // Skip lib type checking
"isolatedModules": true // Enable faster builds
},
"vueCompilerOptions": {
"target": 3.3 // Target Vue 3.3+ for better performance
}
}Vue-tsc not found:
npm install --save-dev vue-tsc typescriptTemplate type errors: Ensure your tsconfig includes Vue files:
{
"include": ["src/**/*.vue", "src/**/*.ts"]
}Script setup issues: Verify Vue version compatibility:
npm install vue@^3.3.0 vue-tsc@^3.0.0Performance issues with large projects:
vueTsc: {
tsconfigPath: './tsconfig.vue.json', // Separate config for Vue files only
buildMode: true, // Enable build optimizations
}Install with Tessl CLI
npx tessl i tessl/npm-vite-plugin-checker