1 typescript 使用
阿新 • • 發佈:2020-08-22
typescript
是JavaScript的超集,由微軟開發
1 使用typescript
下載:npm i typescript -g
單個ts檔案的轉換
命令列執行tsc ./src/index.ts
複雜ts引用情況
1 tsc --init 生成tsconfig.js,即ts配置檔案
2 在配置檔案中設定outDir匯出資料夾,設定mode為amd
3 編輯tsconfig
4 終端-執行任務-開啟ts監視模組
5 使用amd的require.js將入口檔案main.js載入進來
a.ts
export default class Box{ constructor(){ } run(){ console.log("aaa") } } export default class Box{ constructor(){ } run(){ console.log("aaa") } }
b.ts
import Box from './a'
export default class Ball extends Box {
constructor() {
super();
}
run() {
console.log('bbb')
}
}
main.ts
import Ball from './b'
var b = new Ball();
b.run();
index.html
<!-- amd --> <script src="../../require.js" data-main="./js/main"></script> <body> </body>