![](/img/trans.png)
[英]How to disable automatic semicolon for auto imports with TypeScript and JavaScript in Visual Studio Code?
[英]How to make Visual Studio Code use path mappings for automatic imports?
我想在我的項目中使用絕對路徑以避免丑陋的路徑,並在項目樹中的任何文件處進行持續導入。
我在tsconfig.json
中添加了這個
"paths": {
"@myapp/*": ["*", "app/*"]
}
我現在可以使用import {... } from '@myapp/...'
這樣的工作導入,但從 Visual Studio Code 自動導入仍然是相對的。
我在settings.json
中嘗試了這個(如https://blog.angulartraining.com/path-mapping-with-typescript-cac16d12c416中所寫)
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
但這沒有幫助。 如何使 Visual Studio Code 的自動導入使用路徑映射。 另外,是否有工具可以幫助我重構所有代碼?
導航到VSCode上的File>Preferences>Settings>User Settings
設置"typescript.preferences.importModuleSpecifier": "non-relative"
如果您同時擁有 - 映射路徑和相對路徑 - 在PR #40637之后,您可以使用
"typescript.preferences.importModuleSpecifier": "shortest"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.