[TS] TypeScript Config File (tsconfig)
此篇為各筆記之整理,非原創內容,資料來源可見下方連結與文後參考資料。
TSC
$ npx tsc -b . # build
$ npx tsc -b . --clean # 移除掉打包後產生的檔案
$ npx tsc --showConfig > ts-config.txt # 檢視實際上被 TypeScript 處理的檔案(最終吃到的設定檔)
$ npx tsc --project tsconfig.json --diagnostics > ts-diagnostics.txt
多個 tsconfig 時,建議使用 tsc -b 來做檢查
如果專案中有多個 tsconfig
檔案,用 references
把對應的 configuration 組在一起,例如(同時有 tsconfig.node.json
和 tsconfig.app.json
,template-react-ts/tsconfig.json @ GitHub),則使用 tsc -b
來執行才會對每一個 tsconfig 的檔案來做檢查,如果只是執行 tsc
或 tsc --project tsconfig.json
,則可能不會檢查到所有檔案。
參考:
Configuration
- TSConfig Reference @ TypeScript
- The TSConfig Cheat Sheet | Total TypeScript @ Matt Pocock
- React with TypeScript: Best Practices @ SitePoint
- Troubleshooting Handbook: tsconfig.json @ react-typescript-cheatSheet
設定檔
提示
建議可以參考 The TSConfig Cheat Sheet @ Total TypeScript 的設定
如果是用 VS Code 的話,滑鼠移上去 property 就會顯示每個設定的描述:
- compilerOptions
baseUrl
:設成"baseUrl": "./src"
則可以使用 absolute path 來載入模組
include