tools.tsChecker

  • Type: Object | Function
  • Default:
const defaultOptions = {
  typescript: {
    // set 'readonly' to avoid emitting tsbuildinfo,
    // as the generated tsbuildinfo will break ts-checker-rspack-plugin
    mode: 'readonly',
    // enable build when using project reference
    build: useReference,
    // avoid OOM issue
    memoryLimit: 8192,
    // use tsconfig of user project
    configFile: tsconfigPath,
    // resolve the default TypeScript package from user project
    resolveRoot: rootPath,
  },
  issue: {
    // ignore type errors from node_modules
    exclude: [({ file = '' }) => /[\\/]node_modules[\\/]/.test(file)],
  },
  logger: {
    log() {
      // do nothing
      // we only want to display error messages
    },
    error(message: string) {
      console.error(
        message
          .replace(/ERROR/g, 'Type Error')
          .replace(/WARNING/g, 'Type Warning'),
      );
    },
  },
},

By default, the @rsbuild/plugin-type-check is enabled for type checking. You can use output.disableTsChecker config to disable it.

Example

Object Type

When the value of tsChecker is an object, it will be deeply merged with the default configuration.

export default {
  tools: {
    tsChecker: {
      issue: {
        exclude: [({ file = '' }) => /[\\/]some-folder[\\/]/.test(file)],
      },
    },
  },
};

Function Type

When the value of tsChecker 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.

export default {
  tools: {
    tsChecker(options) {
      options.async = false;
      return options;
    },
  },
};

Please refer to @rsbuild/plugin-type-check for more details.

TypeScript Go Support

tools.tsChecker supports enabling TypeScript Go for type checking. This experimental capability is provided by ts-checker-rspack-plugin, which is integrated by @rsbuild/plugin-type-check, and can reduce type-checking time by about 5-10x.

Install TypeScript 7.0 RC to enable TypeScript Go automatically:

npm
yarn
pnpm
bun
deno
npm install typescript@rc -D

You can also install @typescript/native-preview and set typescript.tsgo to true:

npm
yarn
pnpm
bun
deno
npm install @typescript/native-preview -D
export default {
  tools: {
    tsChecker: {
      typescript: {
        tsgo: true,
      },
    },
  },
};

When tsgo is enabled and typescript.typescriptPath is set manually, it must point to an absolute typescript/package.json path from TypeScript 7+ or @typescript/native-preview/package.json.

The @typescript/native-preview usage is deprecated and kept only for compatibility. We recommend installing typescript@rc to use tsgo.

For supported options and limitations, please refer to ts-checker-rspack-plugin - TypeScript Go support.