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

VSCode中types.ts文件出现interface相关ESLint解析错误如何解决?

解决ESLint提示"Unexpected reserved word 'interface'"错误

这个错误是因为ESLint默认用JavaScript解析器处理你的.ts文件,不认识TypeScript特有的语法(比如interface)。按以下步骤修复:

  • 安装TypeScript ESLint依赖
    在项目根目录运行:

    npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
    
  • 配置ESLint支持TypeScript
    找到项目里的ESLint配置文件(比如.eslintrc.js、.eslintrc.json),修改成如下内容:

    module.exports = {
      parser: '@typescript-eslint/parser', // 指定使用TypeScript解析器
      extends: [
        'plugin:@typescript-eslint/recommended' // 启用TypeScript专属ESLint规则
      ],
      plugins: ['@typescript-eslint'],
      env: {
        node: true,
        es6: true
      }
    };
    

    如果项目里还没有tsconfig.json,建议创建一个基础配置文件,让TypeScript解析器能正确识别项目结构:

    {
      "compilerOptions": {
        "target": "ES6",
        "module": "CommonJS",
        "strict": true
      },
      "include": ["src/**/*"]
    }
    
  • 重启VSCode生效
    按Ctrl+Shift+P打开命令面板,选择"Reload Window",让ESLint重新加载配置。

完成以上步骤后,ESLint就能正确识别TypeScript语法,这个错误就会消失了。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.15 09:10:28