01Typescript介绍、安装、开发工具
Typescript 介绍
- TypeScript 是由微软开发的一款开源的编程语言。
- TypeScript 是 Javascript 的超集,遵循最新的 ES6、Es5 规范。TypeScript 扩展了 JavaScript 的语法。
- TypeScript 更像后端 java、C#这样的面向对象语言,可以让 js 开发大型企业项目。
- 谷歌也在大力支持 Typescript 的推广,谷歌的 angular2.x+就是基于 Typescript 语法。
- 最新的 Vue 、React 也可以集成 TypeScript。
- Nodejs 框架 Nestjs、midway 中用的就是 TypeScript 语法。
Typescript 安装 编译
在使用 npm 命令之前电脑必须得安装 nodejs:
1 | npm install -g typescript |
运行:
1 | tsc helloworld.ts |
注意:如果电脑上面没有安装过 cnpm,请先安装 cnpm:
1 | npm install -g cnpm --registry=https://registry.npm.taobao.org |
注意:如果电脑上面没有安装过 yarn 请先安装 yarn:
1 | npm install -g yarn |
Typescript 开发工具 Vscode 自动编译.ts 文件
- 创建 tsconfig.json 文件 tsc –init 生成配置文件 tsconfig.json.
- vscode 点击: 终端->运行任务->typescript->tsc:监视-tsconfig.json 然后就 可以自动生成代码了