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

如何让TypeScript、Eslint在编写违规代码时实时提示错误?

解决远程文件实时TypeScript/ESLint提示问题
  • 改用VS Code Remote - SSH连接远程服务器
    不要直接通过WinSCP打开远程文件,使用VS Code的Remote - SSH扩展建立到服务器的连接,再打开远程项目目录。这样VS Code能完整加载远程环境的依赖与配置,而非仅读取孤立的文件内容。

  • 在远程服务器端安装必要扩展
    连接远程后,在VS Code扩展市场找到ESLint、TypeScript和JavaScript Language Features扩展,选择「Install in SSH: [你的服务器名称]」,确保这些扩展运行在远程环境,而非本地。

  • 配置远程工作区的VS Code设置
    在远程项目的.vscode/settings.json中添加以下配置:

    {
      "eslint.validate": ["typescript"],
      "eslint.run": "onType",
      "typescript.validate.enable": true,
      "typescript.tsdk": "./node_modules/typescript/lib"
    }
    

    其中typescript.tsdk指向项目本地安装的TypeScript库(需确保项目已执行npm install typescript --save-dev),避免VS Code使用本地版本导致环境不兼容。

  • 确认项目依赖与配置文件完整性
    远程项目根目录必须安装核心依赖,执行命令:

    npm install --save-dev typescript eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser
    

    同时确保存在正确的ESLint配置文件(如.eslintrc.js),示例配置:

    module.exports = {
      parser: '@typescript-eslint/parser',
      plugins: ['@typescript-eslint'],
      extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
    };
    
  • 重载远程窗口
    按Ctrl+Shift+P打开命令面板,选择「Remote-SSH: Reload Window」,让所有配置与扩展生效。

完成以上步骤后,编写代码时就能实时看到TypeScript类型错误和ESLint规则的红色下划线提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.22 19:48:17