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

typescript优点

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

编译typescript

tsc

image.png
image.png

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

ts-node

  1. // ts-node 直接编译ts
  2. ts-node 01test.ts

code-Runner

  1. 右击 Run Code