1- 开发环境配置

  1. yarn add typescript -g
  2. yarn add ts-node -g
  3. tsc --version
  4. ts-node --version
  5. cnpm i typescript -g
  6. cnpm i ts-node -g

2- typescript优点

  1. 1.提供了类型校验
  2. 2.ts最终会编译成javascript,所以可以在任何浏览器中运行。
  3. // : 指明变量类型
  4. var s:string = "hello world";


3- 编译typescript

  1. tsc --init

3-1 tsc

1 安装配置 - 图1
1 安装配置 - 图2

  1. //1. tsc编译 将 TypeScript 转换为 JavaScript --tsc 01test.ts
  2. //2. 运行js --node 01test.js

3-2 code-Runner

  1. 安装code-Runner插件
  2. 右击 Run Code

3-3 ts-node

编译后文件存放

image.png
image.png
image.png

编译成功

image.png