入門流程,大神繞行。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.
如今運行試試結果吧。