1. 配置launch.json,其中preLaunchTask中的在task.json中配置
    1. {
    2. // 使用 IntelliSense 了解相关属性。
    3. // 悬停以查看现有属性的描述。
    4. // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    5. "version": "0.2.0",
    6. "configurations": [
    7. {
    8. "type": "node",
    9. "request": "launch",
    10. "name": "启动TS",
    11. "program": "${fileDirname}/${fileBasenameNoExtension}.js",
    12. "preLaunchTask": "tsc-current",
    13. "outFiles": ["${workspaceFolder}/**/*.js"]
    14. }
    15. ]
    16. }
    1. 配置task.json, label与上面使用的相同
    1. {
    2. // See https://go.microsoft.com/fwlink/?LinkId=733558
    3. // for the documentation about the tasks.json format
    4. "version": "2.0.0",
    5. "tasks": [
    6. {
    7. "label": "tsc-current",
    8. "type": "shell",
    9. "command": "tsc ${file} --sourceMap",
    10. "problemMatcher": [
    11. "$tsc"
    12. ]
    13. }
    14. ]
    1. 配置忽略编译的*.js *.map文件,files.exclude配置项
    1. {
    2. "editor.fontSize": 18,
    3. "editor.formatOnSave": true,
    4. "oneDarkPro.italic": false,
    5. "files.exclude": {
    6. "**/*.js": {"when": "$(basename).ts"},
    7. "**/*.map": true,
    8. }
    9. }
    1. 配置tsconfig.json,注意,**module**要选择 **CommonJS**,因为使用node环境跑
    1. {
    2. "compilerOptions": {
    3. "target": "es2015",
    4. "noImplicitAny": true,
    5. "module": "CommonJS",
    6. "outDir": "./ts/build",
    7. "sourceMap": true,
    8. }

    以上配置完成后,在对应ts文件中按F5,就可以编译和调试对应ts文件