TypeScript运行环境安装
前置环境:安装npm,传送门:npm及node.js安装
npm安装后,执行命令:
npm install -g typescript
或者
npm下载较慢,如果安装了cnpm,可以实行以下命令安装:
cnpm install -g typescript
附上cnpm安装语句:
npm install -g cnpm --registry=https://registry.npm.taobao.org
或者,安装了yarn后执行:
yarn global add typescript
运行ts文件命令:cmd中输入:
tsc hello.ts
VSCode中自动编译ts文件
在cmd中切换到当前使用目录,执行:
tsc --init
执行后会创建一个tsconfig.json文件,修改其中一条属性
点击VSCode上方菜单栏,依次点击“终端->运行任务”,在下拉菜单中选择typescript,选择tsc:监视 - tsconfig.json,之后每次编辑完ts文件,VSCode都会帮你自动编译并生成一个js文件