入门流程,大神绕行。node
这就很少说了,安装开发的环境。es6
下载地址:https://code.visualstudio.com/typescript
下载地址:https://nodejs.orgnpm
官网:https://www.typescriptlang.org/
json
官网上,有文档,有视频,有Demo,隐约记得见过中文站,可是如今怎么都找不到了,找到的同窗能够告诉我一下。windows
用node.js的npm安装TypeScript编译器
app
npm install -g typescript
npm install -g typingsthis
typings 主要是用来获取.d.ts文件。当typescript使用一个外部JavaScript库时,会需要这个文件,固然好多的编译器都用它来增长智能感知能力。es5
建一个目录的文件夹,起一个你喜欢的名字。
node项目嘛,固然要先创建一个package.json调试
npm init
跟着提示下一步就行了。
typescript 的项目都须要一个tsconfig.json
tsc --init
会建立一个这样内容的tsconfig.json
{ "compilerOptions": { "module": "commonjs", "target": "es5", "noImplicitAny": false, "sourceMap": false }, "exclude": [ "node_modules" ] }
由于写node.js你能够修改tagget为es6, 要调试把 sourceMap改成true, 添加allowjs为true,就能够ts和js混合玩了.
{ "compilerOptions": { "module": "commonjs", "target": "es6", "noImplicitAny": false, "sourceMap": true, "allowJs": true }, "exclude": [ "node_modules" ] }
仍是由于是node.js开发,咱们要安装node的ts库, 为了强类型,主要仍是为了智能感知。
typings install dt~node --global
国内的用typings 的时候,并且就会抽风,很久都完成不了,没关系,Ctrl+C掉了,再执行,多试几回,总会有成功的时候的。
typings 如今已经不推荐使用了。如今都用npm来弄。
npm install @types/node --dev-save
打开 vscode
code .
windows话 也能够右键菜单,open with Code.
按ctrl + shift + b, 若是没有配置过,task, 就会在上面提示。
选择【配置任务运行程序】
会在.vscode文件夹下生成一个 task.json, 基本不用动,我到如今是没有改过它。
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "0.1.0", "command": "tsc", "isShellCommand": true, "args": ["-p", "."], "showOutput": "silent", "problemMatcher": "$tsc" }
咱们来建立一个app.ts 文件,随便写点东西吧
/** * person */ class person { constructor() { } /** * print */ public print() { console.log('this is a person') } } let p = new person(); p.print();
按Ctrl+Shift+B,编译一下,就会生成一个app.js.
如今运行试试结果吧。