The Type Check plugin provides the ability to run TypeScript type checks in a separate process. The plugin internally integrates with fork-ts-checker-webpack-plugin.
The type checking logic of fork-ts-checker-webpack-plugin
is similar to the native tsc
command of TypeScript. It automatically reads the configuration options from tsconfig.json
and can also be modified via the configuration options provided by the Type Check plugin.
The behavior of the plugin differs in the development and production builds:
You can install the plugin using the following command:
You can register the plugin in the rsbuild.config.ts
file:
The Type Check plugin by default performs checks based on the tsconfig.json
file in the root directory of the current project. Below is an example of a tsconfig.json
file, which you can also adjust according to the needs of your project.
Please note that the fields in tsconfig.json
will not affect the compilation behavior and output of Rsbuild, but will only affect the results of type checking.
Whether to enable TypeScript type checking.
boolean
true
Disable TypeScript type checking:
Enable type checking only during production builds:
Enable type checking only during development builds (it is not recommended to disable type checking during production builds, as it may reduce the stability of the production code):
To modify the options of fork-ts-checker-webpack-plugin
, please refer to fork-ts-checker-webpack-plugin - README to learn about available options.
Object | Function
When the value of forkTsCheckerOptions
is an object, it will be deeply merged with the default configuration.
When the value of forkTsCheckerOptions
is a function, the default configuration will be passed as the first argument. You can directly modify the configuration object or return an object as the final configuration.
ts-loader
in your project and manually configured compileOnly: false
, please disable the Type Check plugin to avoid duplicate type checking.fork-ts-checker-webpack-plugin
check. For details, please refer to: Why are some errors reported as warnings?.Type checking has a significant performance overhead. You can refer to the Performance Guide in the official TypeScript documentation for performance optimization.
For example, properly configuring the include
and exclude
scopes in tsconfig.json
can significantly reduce unnecessary type checking and improve TypeScript performance:
fork-ts-checker-webpack-plugin
does not support checking TypeScript code in .vue
components. You can check for type issues in .vue
files in the following ways:
.vue
files.vue-tsc --noEmit
command to the build
script in package.json:vue-tsc
for type checking, you can disable the Type Check plugin in the production build to avoid redundant checks.