[facebook/create-react-app]怎么关闭终端里的TS报错

2023-12-11 783 views
1

image 虽然项目运行成功, 但是会有很多TS报错打印出来, 浏览器页面也会弹出报错信息覆盖页面

image

expectation: 关闭控制台的TS类型报错, 但不要关闭项目里的类型校验

回答

5

找到办法了 增加如下配置


const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const ForkTsCheckerWarningWebpackPlugin = require('react-dev-utils/ForkTsCheckerWarningWebpackPlugin');

configure: (webpackConfig, { env, paths }) => {
      // 过滤ts类型校验插件
      webpackConfig.plugins = webpackConfig.plugins.filter((item) => {
        if (
          item instanceof ForkTsCheckerWebpackPlugin ||
          item instanceof ForkTsCheckerWarningWebpackPlugin
        ) {
          return false;
        }
        return true;
      });

      return webpackConfig;
    }