TypeScript 學習筆記-模塊
阿新 • • 發佈:2018-10-11
進行 port type scrip tor 輸出 ati pac triangle
可選的模塊加載
import id = require("...")
模塊裏不要使用命名空間
模塊結構上的危險信號
(1)文件的頂層聲明是 export namespace Foo {...},刪除Foo並把所有內容上移
(2)文件只有一個export class或export function 考慮使用export default
命名空間
namespace Name{}
-可以用命名空間來包裹同一作用的代碼
-當項目很大時,可以將這些代碼分離,用相同的命名空間進行包裹
---當涉及到多文件時,我們必須確保所有編譯後的代碼都被加載了:
------(1)將所有文件編譯為一個輸出文件,需要--outFile標記
------ e.g tsc --outFile sample.js Validation.ts LettersOnlyValidator.ts Zi pCodeValidator.ts Test.ts
------(2)編譯每個文件,然後在頁面上通過<script>標簽把文件按照正確的順序引進來
/** * 別名 */ namespace Shape{ export namespace Polygons{ export class Triangle{} export class Square{} } } import Polygons=Shape.Polygons; let sq= new Polygons.Square();
TypeScript 學習筆記-模塊