You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在非TypeScript的React项目中禁用ESLint类型错误?

React非TS项目ESLint类型错误解决思路

1. 清理ESLint配置里的TS相关内容

打开你的ESLint配置文件(.eslintrc.js/.eslintrc.json等):

  • 删除plugins数组里的@typescript-eslint
  • 移除extends字段中plugin:@typescript-eslint/recommended这类TS相关的扩展配置
  • 删除rules里所有带@typescript-eslint/前缀的规则,或直接将它们设为off

2. 卸载TS相关的ESLint依赖

从你的package.json能看到安装了TS版ESLint插件,直接执行卸载命令:

npm uninstall @typescript-eslint/eslint-plugin @typescript-eslint/parser
# 使用yarn的话执行
yarn remove @typescript-eslint/eslint-plugin @typescript-eslint/parser

3. 针对性禁用类型错误规则(若上述步骤未解决)

如果还有残留的类型错误,直接在ESLint配置的rules里关闭对应规则:

{
  "rules": {
    "@typescript-eslint/no-unsafe-assignment": "off",
    "@typescript-eslint/no-unsafe-member-access": "off",
    "@typescript-eslint/no-unsafe-call": "off",
    // 其他出现的类型错误规则都按此格式设为off
  }
}

4. 清理冗余的TS依赖

如果项目完全不使用TypeScript,把package.json里的typescript依赖也卸载:

npm uninstall typescript
# 或执行 yarn remove typescript

5. 重启编辑器和ESLint服务

修改完配置后,重启VS Code(或你使用的编辑器),再重启ESLint服务(VS Code中按Ctrl+Shift+P,搜索ESLint: Restart ESLint Server执行)

内容的提问来源于stack exchange,提问作者Samet Sunman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 17:55:22