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. var s:string = "hello world";
  4. s= 10;

3- 编译typescript

3-1 tsc

image.png
1、 安装配置 - 图2

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

3-2 ts-node

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

3-3 code-Runner

  1. 右击 Run Code

3-4 新建ts项目

  1. npx create-react-app demo --template typescript