zoukankan      html  css  js  c++  java
  • 怎样安装并编译TypeScript?

    1. 使用: npm -v 查看是否安装了 npm ,  如果没有安装, 请前往 Nodejs 官网 下载安装, 下图表示已经安装 npm , 版本为: 6.9.0 .

    PS C:UsersAdministratorDesktop> npm -v
    6.9.0

    2. 使用 tsc -v 查看是否安装了 typescript , 下面表示已经安装, 版本为: 3.5.3, 如果没有安装, 可以使用: npm install -g typescript 进行安装.

    PS C:UsersAdministratorDesktop> tsc -v
    Version 3.5.3
    PS C:UsersAdministratorDesktop> npm install -g typescript

    3. 新建一个 hello.ts 文件, 然后输入以下代码并保存: 

    let hello: string = "Hello, world!";
    console.log(hello);

    4. 打开命令行工具, 使用: tsc ./hello.ts 命令编译 typescript 代码: 

    tsc ./hello.ts

    5. 上述步骤会生成一个 hello.js 的文件, 它是 hello.ts 编译后生成的目标文件, 生成的代码如下所示: 

    var hello = "Hello, World!";
    console.log(hello);

    6. 我们可以使用: node hello.js 直接执行: 

    PS C:UsersAdministratorDesktopdemo> node hello.js
    Hello, World!

    PS: 之后如果对 hello.ts 进行修改, 编译的文件会自动覆盖之前的 hello.js 文件内容, 故无需手动删除.

  • 相关阅读:
    子网掩码的作用与IP网段的划分
    DHCP服务器
    Anaconda安装、更新第三方包
    time模块的使用
    TensorFlow安装
    机器学习-线性回归
    机器学习
    Pyhton-类(2)
    python-类(1)
    Python-函数
  • 原文地址:https://www.cnblogs.com/aisowe/p/11415725.html
Copyright © 2011-2022 走看看