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

Visual Studio Code中TypeScript异常报错:代码运行正常但编辑器提示错误

VS Code中TypeScript编辑器报错但代码运行正常的解决方案

问题现象

  • 代码实际运行完全正常,但VS Code编辑器持续提示多种TypeScript错误,包括:

    • Type expected.(错误代码1110)
    • Cannot find name 'div'.
    • '>' expected.
  • Type expected.错误的详细信息:

[{
    "resource": "/C:/Users/Dell/Desktop/vite-project/src/App.tsx",
    "owner": "typescript",
    "code": "1110",
    "severity": 8,
    "message": "Type expected.",
    "source": "ts",
    "startLineNumber": 10,
    "startColumn": 6,
    "endLineNumber": 10,
    "endColumn": 7
}]
  • 相关界面:VS Code设置异常界面、代码正常运行界面

常见解决方法

  • 对齐TypeScript版本:确保项目本地安装的TypeScript版本与VS Code内置版本一致,点击编辑器右下角TypeScript版本号,选择「Use Workspace Version」切换。
  • 重启TypeScript服务:按下Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),输入TypeScript: Restart TS Server执行。
  • 检查tsconfig.json配置:确认jsx字段设置为react-jsx或react(适配React项目),同时确保目标文件在include列表中,未被exclude规则排除。
  • 清理编辑器缓存:关闭VS Code,删除项目根目录下的.vscode文件夹(建议先备份),重启后重新加载项目。
  • 排查扩展冲突:暂时禁用所有VS Code扩展,逐个重新启用,定位是否有扩展干扰TypeScript语法校验。

内容的提问来源于stack exchange,提问作者B A.J Amar

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 14:04:53