typescript學習(1)配置、編譯
阿新 • • 發佈:2021-01-20
技術標籤:學習記錄雜七雜八typescript前端
做一些總結與記錄:
檢視index.ts檔案執行結果:
1、tsc --outFile ./js/index.js index.ts 即可將根目錄ts檔案轉為js檔案,node index.js即可執行此js檔案
2、使用ts-node:npm install ts-node -g;mac安裝失敗可以加sudo;安裝完成之後直接:ts-node index.ts即可檢視ts檔案執行結果
3、配置tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "outDir": "./js", "strict": true, "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true } }
- tsc --init 初始化tsconfig.json檔案如上(其他配置已經刪除),其中設定outDir可以指定對應目錄
- vscode中選擇 終端->執行任務->選擇tsc監視即可;或者直接終端輸入 tsc --watch
- 在ts中寫入內容即可在outDir實時輸出js檔案 node index.js檢視結果