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 badges
Add a ment  | 

2 Answers 2

Reset to default 10
  1. Navigate toFile>Preferences>Settings>User Settings on VSCode

  2. Set "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