在 VSCode 中开发 TypeScript

参考: TypeScript tutorial in Visual Studio Code

安装 Node.js

  • 下载并安装 Node.js
    node --version
    npm --version
    

安装 ts-node 和 Typescript

  • 安装Typescript

    npm install -g typescript
    
  • 安装 ts-node. 安装后能直接运行 .ts文件, 不需要通过tsc编译.

    npm install -g ts-node
    
  • 打印版本信息测试安装.

    tsc --version
    ts-node --version
    
  • 安装 Visual Studio Code

创建测试工程

  • 创建测试目录并使用code打开
    mkdir HelloWorld
    cd HelloWorld
    code .
    
  • 创建测试文件helloworld.ts, 并在文件中添加如下内容
    let message: string = 'Hello World';
    console.log(message);
    

运行和调试

  • 点击左侧活动面板中的"运行和调试面板", 选择"create a launch.json file", 选择 Node.js “环境”. 或通过菜单"Run | Open Configurations" 同样可以完成此步骤.
    在这里插入图片描述
  • 打开 .vscode/launch.json, 将文件内容替换如下:
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
      {
          // 运行当前文件. 如果是固定某个文件, 请替换掉${file}
          "command": "ts-node ${file}",
          "name": "Launch Program",
          "request": "launch",
          "type": "node-terminal"
      }
  ]
}
  • 编辑器切换到helloworld.ts文件, 然后点击 “运行与调试面板” 上的 启动调试 按钮, 或使用F5快捷键启动调试.
    在这里插入图片描述
  • 启动调试执行完成后, 在终端窗口(TERMINAL)显示如下内容, 同时在调试控制台(DEBUG CONSOLE)中打印 “hello world”.
    在这里插入图片描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

falwat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值