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


    13167242-eafb2fe90805a4ca.png
    ts文件

    tsc 转译

13167242-760700844851e956.png
转译之后生成的

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

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

13167242-64f2ac4225e26acb.png
报错

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

public

13167242-4d54b32543592a6f.png
image.png

相当于


13167242-62e31fe9f2363cd7.png
image.png

代表公开属性

猜你喜欢

转载自blog.csdn.net/weixin_34232744/article/details/86897773