TS 安装(hello world)

安装

npm install typescript -g
npm install ts-node -g (node 需要这个来识别ts)
windows用户要在项目当前安装ts-node

创建一个hello world

  • 浏览器可以运行Js
  • 浏览器不可以运行ts
  • ts 需要转译为js 名为type script compiler (tsc)
  1. touch greeter.ts
  2. 在命令行中输入 tsc greeter.ts
    生成了gretter.js


    ts文件

    tsc 转译

转译之后生成的

貌似没什么变化 尝试一些改变

将上面的user转变为数组[1,2,3,4]

报错

tsc 会进行类型检查使之不能进行转译
即在还没执行到的时候就可以检查出来错误

public

image.png

相当于


image.png

代表公开属性

你可能感兴趣的:(TS 安装(hello world))