# [VSCode 小技巧] TypeScript 排除不想要自動 import 的套件 ## 情境 我在 VSCode 都會定義一些方便開發的常用 Snippets,例如輸入 `af` (arrow function 的縮寫) 便會自動帶出 `(arguments) => statement`。 然而最近在某些專案上工作時,發現我的 Snippets 不一定會出現在 Intellisense 選單的第一個結果,而是被其他套件的匯出霸佔,例如的 `date-fns/locale` 的 `af`。 而這些匯出其實很罕用,99% 的時間都用不到,導致我總是要按多次方向鍵才能選到想要的項目。 ![Screenshot 2025-11-15 at 15.09.18](https://hackmd.io/_uploads/HJXEPoHebl.png) ## 解決方法 在 VSCode 可以設定 `typescript.preferences.autoImportFileExcludePatterns` 來排除不想要自動 import 的項目,例如新增 `node_modules/date-fns/locale/**`,**重啟 VSCode 後**便會發現選單恢復預期的結果了。 ![Screenshot 2025-11-15 at 15.24.51](https://hackmd.io/_uploads/r1S05sreWg.png) ![Screenshot 2025-11-15 at 15.28.08](https://hackmd.io/_uploads/BJT5isrg-g.png) ## Reference - [Exclude specific files from auto import suggestions · Issue #35395 · microsoft/TypeScript](https://github.com/microsoft/TypeScript/issues/35395#issuecomment-1728399446)