【问题标题】:Why VS Code fails to debug sources with TS 3.7.1-rc syntax support?为什么 VS Code 无法调试具有 TS 3.7.1-rc 语法支持的源代码?
【发布时间】:2025-12-08 08:20:04
【问题描述】:

我有一个代码库,我愿意使用typescript 3.7,确切地说我使用3.7.1-rc。我可以使用命令行构建源代码,甚至可以在命令行中运行测试,但是当我想使用F5 调试项目时,它失败了,vs code 声称有一些错误,但它在@987654325 中没有显示任何内容@ 选项卡,但在 Outputs 中显示:

sample.ts(42,53): error TS1109: Expression expected.
sample.ts(42,68): error TS1005: ':' expected.

源文件如下所示:

if (filterElements || configuration.classes?.filterElements) {
            const filter = filterElements || configuration.classes!.filterElements;

其中第 53 列是问号所在的位置,第 68 列是右括号所在的位置。我什至尝试过 VS Code Insider,它的行为是一样的。

我不知道该怎么做。在我使用?3.7 的地方,我遇到了同样的错误。

【问题讨论】:

  • 您是否也将 VS Code 设置为使用您的 TypeScript 版本?右下角There's this version number可以点击设置。
  • 是的,这就是为什么它在Problems 选项卡上没有显示错误

标签: typescript visual-studio-code vscode-debugger


【解决方案1】:

这里有一个link 可以在 GitHub 上讨论如何解决问题。

简短回答:全局安装typescript@3.7.1-rc,或配置task.json文件以引用本地安装的tsc(这与VS Code选择的版本不同。

task.jsonproblemMatcher 配置为指向本地安装的 tsc

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "tsc",
            "type": "typescript",
            "tsconfig": "tsconfig.json",
            "problemMatcher": [
                {
                    "base": "$tsc",
                    "fileLocation": [
                        "relative",
                        "${workspaceRoot}/node_modules/typescript/lib"
                    ]
                }
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
}

【讨论】: