VSCode debugging TS code configuration method

Configuration steps

    VSCode needs to be configured to debug TS code. The following describes the configuration steps

1 The first step is to prepare the ts file to be debugged.
Create a new a.ts file as the ts file to be debugged

console.log('1 准备开始执行 for 循环')

for (let i: number = 1; i <= 3; i++) {
  console.log('...一锅装不下')
}

console.log('2 for 循环执行结束')

 

2 The second step  to open the debug window: click on the left column penultimate event button (Debug)

Generate default configuration: click the drop-down box behind DEBUG, select add configuration

Modify the configuration content as follows:

{
  // 使用 IntelliSense 了解相关属性。 
  // 悬停以查看现有属性的描述。
  // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "调试TS代码",
      // ts-node 命令: “直接”运行ts代码。
      // 作用:调试时加载ts-node包(在调试时“直接”运行ts代码)
      "runtimeArgs": ["-r", "ts-node/register"],
      // 此处的 a.ts 表示要调试的 TS 文件( 可修改为其他要调试的ts文件 )
      "args": ["${workspaceFolder}/a.ts"]
    }
  ]
}

3The third step is to install and debug the packages used

In the current directory, open a terminal window

Enter the following command in the terminal:

# 注意:原来通过 -g(全局)安装的包,在调试时不生效,需要在当前目录中单独安装
# 调试TS代码,依赖这两个包
npm i ts-node typescript

Debugging skills

View console.log output (debug console)

Monitor the value of the variable (1. Move the mouse in; 2. Add to the left monitoring window)

Guess you like

Origin blog.csdn.net/cz_00001/article/details/112919409