TypeScript
The TypeScript checker reports type errors in .ts and .tsx files, using your project's tsconfig.json. Use it for vanilla TypeScript, React, and other projects without framework-specific files. For Vue, use vue-tsc; for Svelte, use svelte-check.
Set up
Install TypeScript:
bashpnpm add -D typescriptbashnpm install -D typescriptbashyarn add -D typescriptbashbun add -d typescriptEnable the checker:
tschecker({ typescript: true, })
In dev mode, the checker uses the TypeScript watch API with noEmit. In build mode, it runs tsc --noEmit.
Use a different tsconfig
By default, the checker looks for tsconfig.json in the Vite root. To use another file, set tsconfigPath:
checker({
typescript: {
tsconfigPath: 'tsconfig.app.json',
},
})Project references
If your tsconfig uses project references, the checker can run in build mode (tsc --build), which checks every referenced project.
Build mode turns on automatically when the tsconfig is solution-style: "files": [], no include, and at least one entry in references. The react-ts template of create-vite generates this layout. To turn it on or off explicitly, set buildMode:
checker({
typescript: {
buildMode: true,
},
})--build doesn't accept --noEmit (TypeScript#36917), so tsc follows the emit settings of each referenced project. Set "noEmit": true in referenced projects that shouldn't write output, as the create-vite templates do.
TypeScript 7
The checker has experimental support for TypeScript 7 (the native Go port). When the installed typescript package is version 7, dev mode runs tsc --watch as a child process instead of using the watch API.
Options
| Option | Type | Default | Description |
|---|---|---|---|
root | string | Shared root | Directory to resolve tsconfigPath from. |
tsconfigPath | string | 'tsconfig.json' | Path to the tsconfig file, relative to root. |
buildMode | boolean | true for solution-style tsconfigs, otherwise false | Run tsc with --build. See Project references. |
typescriptPath | string | 'typescript' | Module specifier or absolute path of the typescript package to use in dev mode. Build mode always runs the tsc binary installed in your project. |
