# [VSCode 小技巧] TypeScript 排除不想要自動 import 的套件 ## 情境 我在 VSCode 都會定義一些方便開發的常用 Snippets,例如輸入 `af` (arrow function 的縮寫) 便會自動帶出 `(arguments) => statement`。 然而最近在某些專案上工作時,發現我的 Snippets 不一定會出現在 Intellisense 選單的第一個結果,而是被其他套件的匯出霸佔,例如的 `date-fns/locale` 的 `af`。 而這些匯出其實很罕用,99% 的時間都用不到,導致我總是要按多次方向鍵才能選到想要的項目。  ## 解決方法 在 VSCode 可以設定 `typescript.preferences.autoImportFileExcludePatterns` 來排除不想要自動 import 的項目,例如新增 `node_modules/date-fns/locale/**`,**重啟 VSCode 後**便會發現選單恢復預期的結果了。   ## Reference - [Exclude specific files from auto import suggestions · Issue #35395 · microsoft/TypeScript](https://github.com/microsoft/TypeScript/issues/35395#issuecomment-1728399446)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up