admin管理员组文章数量:1356266
I want to have absolute paths in my project to avoid ugly paths and to have constant imports wherever a file is in the project tree.
I have added this in the tsconfig.json
"paths": {
"@myapp/*": ["*", "app/*"]
}
I can now have working imports like import { ... } from '@myapp/...'
but the automatic imports from Visual Studio Code are still relative.
I tried this in the settings.json
(as written in )
"editor.codeActionsOnSave": {
"sourceanizeImports": true
}
But it didn't help. How to make Visual Studio Code's automatic imports use the paths mapping. Also, is there a tool that would help me refactor all of my code?
I want to have absolute paths in my project to avoid ugly paths and to have constant imports wherever a file is in the project tree.
I have added this in the tsconfig.json
"paths": {
"@myapp/*": ["*", "app/*"]
}
I can now have working imports like import { ... } from '@myapp/...'
but the automatic imports from Visual Studio Code are still relative.
I tried this in the settings.json
(as written in https://blog.angulartraining./path-mapping-with-typescript-cac16d12c416)
"editor.codeActionsOnSave": {
"sourceanizeImports": true
}
But it didn't help. How to make Visual Studio Code's automatic imports use the paths mapping. Also, is there a tool that would help me refactor all of my code?
Share Improve this question asked Sep 2, 2019 at 18:44 Guerric PGuerric P 31.9k6 gold badges58 silver badges106 bronze badges2 Answers
Reset to default 10Navigate to
File>Preferences>Settings>User Settings
on VSCodeSet
"typescript.preferences.importModuleSpecifier": "non-relative"
If you have both - mapped paths & relative - after PR #40637 you can use
"typescript.preferences.importModuleSpecifier": "shortest"
本文标签: javascriptHow to make Visual Studio Code use path mappings for automatic importsStack Overflow
版权声明:本文标题:javascript - How to make Visual Studio Code use path mappings for automatic imports? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744001249a2573897.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论