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"