---
title: "TypeScript 7.1 進入 RC　新增 import attributes 與 source phase imports"
url: https://sammy.hk/typescript-7-1-rc/
author: Ethan
published: 2026-12-05T19:12:00+08:00
modified: 2026-12-05T19:12:00+08:00
description: "TypeScript 團隊公布 7.1 Release Candidate，開發者可透過 npm install -D typescript@rc 試用。RC 在 7.1 Beta 的基礎上補充 API、內容映射套件與預設值調整，新增 &#8211;disableDynamicImportExtensionRewrit…"
categories: ["開放源碼"]
tags: [JavaScript, TypeScript, "版本更新", "程式語言"]
source: https://sammy.hk
---
TypeScript 團隊公布 7.1 Release Candidate，開發者可透過 npm install -D typescript@rc 試用。RC 在 7.1 Beta 的基礎上補充 API、內容映射套件與預設值調整，新增 –disableDynamicImportExtensionRewriting 旗標，並發布實驗性 WebAssembly 套件，讓編譯器可在瀏覽器及 WASI 環境運行。官方基準測試顯示，7.1 RC 在多個大型開源專案上比 TypeScript 7 快 1.2 至 2.2 倍，記憶體用量減少約 26.6% 至 49.2%。\[1\]

## 語言層面的新增功能

7.1 讓環境模組宣告（ambient module declaration）支援 import attributes，開發者可寫出 declare module “\*” with { type: “css” } 一類宣告，按屬性分別給予型別。若匯入時漏寫所需屬性，編譯器會報錯；符合宣告的匯入則按屬性取得對應型別，例如 type: “css” 取得 CSSStyleSheet，type: “text” 取得 string，type: “bytes” 取得 Uint8Array。官方提醒，這類宣告不會內建於 lib，亦建議套件作者不要自行發布，由使用者在專案內聲明，以免與未來的內建宣告衝突。\[2\]

另一項功能是 source phase imports。import source 與 import.source() 會取得模組在解析之後、載入依賴之前的中間物件，型別為新增的全域型別 AbstractModuleSource；WebAssembly 模組會是 WebAssembly.Module，可直接交給 WebAssembly.instantiate。此功能要求 –module 設為 esnext、nodenext 或 preserve，並配合 esnext 的 lib 或 target。\[1\]

## 標準庫與工具鏈

7.1 支援以 es2026 作為穩定的 –target 與 –lib 選項，把已定案的 ECMAScript 2026 功能由 esnext 移入，包括 Math.sumPrecise()、Iterator.concat()、JSON.rawJSON()、Error.isError()、Map 與 WeakMap 的 getOrInsert 系列、Uint8Array 的 toBase64 與 toHex 系列，以及 Array.fromAsync()。esnext 則加入 Promise.allKeyed、Promise.allSettledKeyed、Iterator.zip、Iterator.zipKeyed 與 Iterator.prototype.chunks 等提案。

編譯器 API 亦重新組織，分為 typescript/sync、typescript/async、typescript/fs、typescript/ast、typescript/ast/is、typescript/ast/factory 等進入點，另有實驗性的 typescript/wasm。官方說明，新 API 不會自行尋找或載入 tsconfig.json，亦不支援 –project，使用時須自行傳入檔案與編譯選項。

此外，RC 新增 –disableDynamicImportExtensionRewriting 旗標，讓開發者關閉動態匯入的路徑改寫；內容映射套件亦加入更強的功能與預設值。實驗性 WebAssembly 套件以 wasip1 為目標，需要安裝 @typescript/typescript-wasip1 方可使用，適合在瀏覽器或 WASI 執行環境中直接進行型別檢查。

## 效能與升級注意

官方以四個型別檢查執行緒、–noEmit 模式量度，多個專案的編譯時間明顯下降：mui-docs 由 19.1 秒降至 8.77 秒，t3code-server 由 23 秒降至 16.9 秒，vscode 由 19.4 秒降至 14.9 秒，bluesky 由 3.97 秒降至 3.3 秒。記憶體方面，mui-docs 由 7,043 MiB 降至 3,580 MiB，vscode 由 8,401 MiB 降至 6,162 MiB，減幅約四分之一至一半。\[1\]

升級時須留意一項行為變更：分散式型別參數（distributive type parameters）的檢查更嚴格。在條件型別中，分支內的型別參數會被視為原參數的子集，與其他以原參數為約束的型別再無關係；過往可通過的寫法，會出現「Type ‘B’ does not satisfy the constraint ‘A’」錯誤，需要移除多餘約束，或加上額外條件檢查。DOM 的 lib.d.ts 更新亦可能令既有專案出現新的型別錯誤，建議先在小範圍專案試升級。\[1\]

## 參考資料

\[1\] [Announcing TypeScript 7.1 RC（2026 年 12 月）](https://devblogs.microsoft.com/typescript/announcing-typescript-7-1-rc/)

\[2\] [microsoft/TypeScript 合併請求 #63931：環境模組宣告支援 import attributes](https://github.com/microsoft/TypeScript/pull/63931)

### 相關文章：

1. [PHP 8.6 正式推出 加入局部函數應用與新輪詢 API](https://sammy.hk/php-8-6-released/ "PHP 8.6 正式推出 加入局部函數應用與新輪詢 API")
2. [GitHub 用 AI 代理把 Copilot 執行時重寫為 Rust：832,378 行與 96% 提示快取命中](https://sammy.hk/github-%e7%94%a8-ai-%e4%bb%a3%e7%90%86%e6%8a%8a-copilot-%e5%9f%b7%e8%a1%8c%e6%99%82%e9%87%8d%e5%af%ab%e7%82%ba-rust%ef%bc%9a832378-%e8%a1%8c%e8%88%87-96-%e6%8f%90%e7%a4%ba%e5%bf%ab%e5%8f%96%e5%91%bd/ "GitHub 用 AI 代理把 Copilot 執行時重寫為 Rust：832,378 行與 96% 提示快取命中")
3. [Zig 0.17 發布：建置系統重新設計，增量編譯預期全面可用](https://sammy.hk/zig-0-17-%e7%99%bc%e5%b8%83%ef%bc%9a%e5%bb%ba%e7%bd%ae%e7%b3%bb%e7%b5%b1%e9%87%8d%e6%96%b0%e8%a8%ad%e8%a8%88%ef%bc%8c%e5%a2%9e%e9%87%8f%e7%b7%a8%e8%ad%af%e9%a0%90%e6%9c%9f%e5%85%a8%e9%9d%a2%e5%8f%af/ "Zig 0.17 發布：建置系統重新設計，增量編譯預期全面可用")
4. [Python 3.15.0 正式版發布：實驗性 JIT 明顯加速、UTF-8 成預設編碼](https://sammy.hk/python-3-15-0-%e6%ad%a3%e5%bc%8f%e7%89%88%e7%99%bc%e5%b8%83%ef%bc%9a%e5%af%a6%e9%a9%97%e6%80%a7-jit-%e6%98%8e%e9%a1%af%e5%8a%a0%e9%80%9f%e3%80%81utf-8-%e6%88%90%e9%a0%90%e8%a8%ad%e7%b7%a8%e7%a2%bc/ "Python 3.15.0 正式版發布：實驗性 JIT 明顯加速、UTF-8 成預設編碼")
