Install any skill in seconds. Free to start, no credit card required.
Get Started Free →協助設定和維護 TypeScript 專案配置。 使用時機: - 建立/更新 tsconfig.json - 診斷配置問題 - 升級 TypeScript 版本 - 理解 compilerOptions - 配置 monorepo - 整合特定框架 觸發關鍵字: - tsconfig - compilerOptions - TypeScript 升級 - strict mode - type definitions - module resolution - target/lib/types
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 13% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 2% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 69% | 0% |
| case-16 | ✓→✓ | = Same ✓ | 42% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 3% | 0% |
提供 TypeScript 專案配置的實用指導,包含 tsconfig.json 設定、編譯選項解釋、版本升級指南與問題診斷。
Property 'fromEntries' does not exist
原因 (WHY): Object.fromEntries 等新 API 屬於較新的 ECMAScript 標準。如果 tsconfig.json 中的 lib 或 target 配置過舊(例如 ES2015),TypeScript 編譯器就不會載入對應的內建型別聲明,導致編譯失敗。
做法 (WHAT): 提升 lib 版本至包含該 API 的 ECMAScript 標準(如 ES2022 或更新版本)。
json{ "compilerOptions": { "lib": [ "ES2022" ] } }
變更: TypeScript 6 不再自動載入 node_modules/@types 下的所有型別定義。
原因 (WHY):
做法 (WHAT): 必須在 compilerOptions.types 中明確列出專案所依賴的全域型別(如 node、jest 等),否則編譯時會出現 "Cannot find name" 錯誤。
json{ "compilerOptions": { "types": [ "node", "jest" ] } }
變更: 提供 ignoreDeprecations 選項以抑制特定版本的棄用警告。
原因 (WHY): 專案在升級至 TypeScript 6.0 時,可能仍包含已被棄用或將移除的舊版配置項。此選項允許團隊在不被大量編譯警告阻塞的情況下完成升級,爭取時間逐步重構與清理技術債。
做法 (WHAT):
json{ "compilerOptions": { "ignoreDeprecations": "6.0" } }
當遇到編譯問題時,按以下項目進行檢查,以釐清問題根源:
types 和 @types/* 安裝"Cannot find name" 錯誤。lib 版本"Property X does not exist on type Y"。moduleResolutionnode、bundler 等)與實際運行環境相符,否則會出現 "Cannot find module" 錯誤。include / exclude 路徑Other measured skills in the registry, with their headline benchmark lift.