Typescript安装/编译
安装Typescript,需首先安装Nodejs
安装Typescript
npm install -g typescript# 或者使用cnpm进行安装cnpm install -g typescript
编译Typescript
编写好index.ts文件后,进入该文件夹
tsc index.js
VScode配置自动编译ts文件
- 在项目文件夹中运行命令,生成tsconfig.json
tsc --init
- 修改tsconfig.json文件,将
outDir修改为编译后的js保存路径,例如{"outDir": "./js"}
点击VScode菜单栏的
终端或任务,选择运行任务在弹出的菜单中选择
tsc 监视 - tsconfig.json
