Vue Type Checker

3.2.7 · active · verified Sun Apr 19

vue-tsc is a command-line tool designed to integrate TypeScript's `tsc` compiler with Vue's Single File Components (SFCs). It functions as a wrapper around `tsc`, enabling full TypeScript type-checking and declaration file generation for `.vue` files by transforming them into virtual TypeScript code. The current stable version is 3.2.7, part of the actively developed `vuejs/language-tools` monorepo, receiving frequent updates with several patch releases per month. Its key differentiator is providing robust, performant type-checking for Vue applications within existing TypeScript ecosystems, leveraging `tsconfig.json` for configuration. It requires TypeScript 5.0.0 or higher as a peer dependency.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic execution of `vue-tsc --noEmit` to type-check Vue SFCs in a project. It sets up a minimal `tsconfig.json` and a `.vue` file for context.

import { run } from 'vue-tsc';
import * as path from 'path';
import * as fs from 'fs';

// Create a dummy tsconfig.json for demonstration if not present
const tsconfigPath = path.resolve('./tsconfig.json');
if (!fs.existsSync(tsconfigPath)) {
  fs.writeFileSync(tsconfigPath, JSON.stringify({
    "compilerOptions": {
      "target": "esnext",
      "module": "esnext",
      "moduleResolution": "bundler",
      "strict": true,
      "jsx": "preserve",
      "lib": ["esnext", "dom"],
      "types": ["node", "vue"]
    },
    "vueCompilerOptions": {
      "extensions": [".vue"]
    },
    "include": ["./**/*.ts", "./**/*.d.ts", "./**/*.vue"]
  }, null, 2));
}

// Create a dummy Vue SFC for type checking
const vueFilePath = path.resolve('./MyComponent.vue');
if (!fs.existsSync(vueFilePath)) {
  fs.writeFileSync(vueFilePath, `
<script setup lang="ts">
import { ref } from 'vue';
const message: string = ref('Hello Vue 3 and TypeScript').value;
// Intentional error for demonstration: assign number to string
// const errorVal: string = 123; 
</script>

<template>
  <div>{{ message }}</div>
</template>
`);
}

console.log('Running vue-tsc programmatically with --noEmit...');

// Execute vue-tsc with command-line arguments
try {
  run({
    args: ['--noEmit', '--project', tsconfigPath] // Equivalent to 'vue-tsc --noEmit --project ./tsconfig.json'
  });
  console.log('vue-tsc completed successfully (noEmit). No type errors found.');
} catch (e) {
  console.error('vue-tsc encountered an error:', e.message);
  console.error('Check MyComponent.vue for type errors or tsconfig.json configuration.');
  process.exit(1);
}

view raw JSON →