TypeScript 定義型別時 file.d.ts 與 file.ts 的檔名有什麼差別?What’s the difference between file.d.ts and file.ts in TypeScript

先下個結論,使用 file.ts 與 file.d.ts 來定義 type 或 interface 時的差別是,不使用 import export 的前提下 file.ts 預設 scope 為 local,file.d.ts 預設則為 global 。整個專案目錄裡可以不用 import MyType 就可以直接使用 MyType 這個型別,且 .d.ts 的檔案在編譯時不會被轉成 JavaScript 檔案。

原文出處:TypeScript 定義型別時 file.d.ts 與 file.ts 的檔名有什麼差別?What’s the difference between file.d.ts and file.ts in TypeScript

Leave a Reply