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

如何在ESLint.js文件中配置TypeScript分号规则?

解决TypeScript中ESLint分号错误问题

你的ESLint配置是.js格式,只需将@typescript-eslint/semi规则正确添加到rules对象中即可。JS配置里,属性名包含@这类特殊字符时,需要用引号包裹(单引号或双引号均可),这是之前添加规则出错的核心原因。

修改后的完整配置代码如下:

module.exports = {
  env: {
    browser: true,
    es2021: true
  },
  extends: [
    'plugin:react/recommended',
    'plugin:react/jsx-runtime',
    'standard-with-typescript'
  ],
  overrides: [],
  parserOptions: {
    ecmaVersion: 'latest',
    sourceType: 'module',
    project: ['./tsconfig.json']
  },
  plugins: ['react'],
  rules: {
    semi: 'off',
    '@typescript-eslint/semi': 'warn'
  }
};

关键说明

  • 必须关闭基础的semi规则,避免和TypeScript专属规则产生冲突
  • 规则值设为warn时,出现多余分号会触发警告;如果要强制要求使用分号,可改为error,不符合规则时直接抛出错误

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 06:20:26