在 Visual Studio 代码中使用 ts 节点键入 TypeScript

将 ts 节点添加到 TypeScript 项目:

npm i ts-node

添加脚本到 package.json

"start:debug": "ts-node --inspect=5858 --debug-brk --ignore false index.ts"

需要将 launch.json 配置为使用 node2 类型并启动运行 start:debug 脚本的 npm:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node2",
            "request": "launch",
            "name": "Launch Program",
            "runtimeExecutable": "npm",
            "windows": {
                "runtimeExecutable": "npm.cmd"
            },
            "runtimeArgs": [
                "run-script",
                "start:debug"
            ],
            "cwd": "${workspaceRoot}/server",
            "outFiles": [],
            "port": 5858,
            "sourceMaps": true
        }
    ]
}