[英]How to make Visual Studio Code use path mappings for automatic imports?
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
我在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.我现在可以使用import {... } from '@myapp/...'
这样的工作导入,但从 Visual Studio Code 自动导入仍然是相对的。
I tried this in the settings.json
(as written in https://blog.angulartraining.com/path-mapping-with-typescript-cac16d12c416 )我在settings.json
中尝试了这个(如https://blog.angulartraining.com/path-mapping-with-typescript-cac16d12c416中所写)
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
But it didn't help.但这没有帮助。 How to make Visual Studio Code's automatic imports use the paths mapping.如何使 Visual Studio Code 的自动导入使用路径映射。 Also, is there a tool that would help me refactor all of my code?另外,是否有工具可以帮助我重构所有代码?
Navigate to File>Preferences>Settings>User Settings
on VSCode 导航到VSCode上的File>Preferences>Settings>User Settings
Set "typescript.preferences.importModuleSpecifier": "non-relative"
设置"typescript.preferences.importModuleSpecifier": "non-relative"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.