技能 migrate-to-shoehorn
📦

migrate-to-shoehorn

低風險 ⚙️ 外部命令

將 TypeScript 測試遷移至 Shoehorn

TypeScript 測試常使用不安全的 `as` 斷言來偽造大型物件。此技能可將其遷移至型別安全的 shoehorn 輔助函式,同時保持自動完成和型別檢查的正常運作。

支援: Claude Codex Code(CC)
🥉 72 青銅
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「migrate-to-shoehorn」。 getUser({ body: { id: '123' } } as Request);

預期結果:

遷移後:getUser(fromPartial({ body: { id: '123' } }));並從 @total-typescript/shoehorn 加入對應的 import。

正在使用「migrate-to-shoehorn」。 getUser({ body: { id: 123 } } as unknown as Request);

預期結果:

遷移後:getUser(fromAny({ body: { id: 123 } }));並從 @total-typescript/shoehorn 加入對應的 import。

安全審計

低風險
v1 • 6/12/2026

All 37 static findings are false positives. The 'backtick execution' detections are Markdown code fences around TypeScript examples. The 'weak cryptographic algorithm' and 'system reconnaissance' flags are pattern false-positives from prose matching. The skill is benign documentation that guides migration of test code to use @total-typescript/shoehorn. No malicious intent detected.

1
已掃描檔案
119
分析行數
2
發現項
1
審計總數
低風險問題 (1)
Shell command examples in documentation
SKILL.md contains bash and grep command examples (npm install, grep search). These are instructional, not executed.
審計者: claude

品質評分

38
架構
100
可維護性
87
內容
50
社群
88
安全
91
規範符合性

你能建構什麼

遷移測試中的大型 mock 物件

使用 fromPartial() 取代冗長的大型 TypeScript 型別偽造物件,僅傳遞必要的屬性。

取代不安全的雙重 as 斷言

將 `as unknown as Type` 模式轉換為 fromAny(),用於錯誤測試情境。

標準化測試資料輔助函式

在整個程式碼庫的測試套件中一致地採用 shoehorn,以提升型別安全性。

試試這些提示

基本遷移請求
Find all test files using `as Type` assertions and migrate them to use fromPartial() from @total-typescript/shoehorn.
遷移雙重 as 模式
Replace all `as unknown as Type` patterns in my test files with fromAny() from @total-typescript/shoehorn.
遷移大型物件偽造資料
I have test files that fake large Request objects with 20+ properties. Migrate them to use fromPartial() so I only specify the properties I need.
完整稽核與遷移
Audit my test suite for all `as` assertions, install @total-typescript/shoehorn, and migrate every occurrence to the appropriate shoehorn helper.

最佳實務

  • 對於僅有部分屬性與測試相關的大型物件,使用 fromPartial()
  • 僅在刻意傳遞錯誤型別的資料以進行錯誤測試時,才使用 fromAny()
  • 將 shoehorn 的使用限制在測試檔案中,絕不用於正式環境程式碼
  • 遷移後執行型別檢查,以確認型別安全性仍獲得保留

避免

  • 在正式環境的原始碼中使用 shoehorn 輔助函式
  • 未確認型別檢查仍通過便進行遷移
  • 在 fromPartial() 即可滿足需求時卻使用 fromAny(),從而失去型別安全性的優勢
  • 遺留部分 `as` 斷言未遷移,造成測試模式不一致

常見問題

什麼是 shoehorn?
Shoehorn 是一個 TypeScript 函式庫,讓您在測試中傳遞部分資料的同時,仍保持完整的型別安全性和自動完成功能。
Shoehorn 可以在正式環境的程式碼中使用嗎?
不行。Shoehorn 僅設計用於測試程式碼。在正式環境中使用可能會掩蓋真實的型別錯誤。
如何安裝 shoehorn?
在您的專案中執行 `npm i @total-typescript/shoehorn` 即可新增此套件。
fromPartial 和 fromAny 之間有什麼差別?
fromPartial() 用於仍能正確通過型別檢查的資料;fromAny() 則用於刻意錯誤的資料,例如錯誤測試案例。
如何找到含有 `as` 斷言的測試檔案?
使用技能工作流程中顯示的 grep 指令,在測試檔案中尋找符合 ` as [A-Z]` 的檔案。
此技能會自動執行程式碼嗎?
不會。此技能僅提供指引和範例,實際的指令執行和編輯由您自行完成。

開發者詳情

檔案結構

📄 SKILL.md