VSCode after the last update now knows how to automatically add imports. However it adds using relative paths - any idea if that is somehow configurable?
1 Answer
It is configurable if you are using VS Code 1.24 and TypeScript >= 2.9.
From the release notes,
Preferences for auto imports and generated code
You can now explicitly specify the quote and path styles that VS Code uses for auto imports and other generated JavaScript and TypeScript code.
[...]
The
javascript.preferences.importModuleSpecifierandtypescript.preferences.importModuleSpecifiersettings specify the type of path to use for imports.Valid values are:
"relative"to the file location."non-relative"based on thebaseUrlconfigured in yourjsconfig.json/tsconfig.json."auto"to infer the shortest path type.These new preferences require TypeScript 2.9+.
2 Comments
Aidin
Thanks! Was a life-saver. I am using tsconfig-paths and I like all the paths to be absolute. This really helped!
Webia1
In my case, working with NxMonoRepo v16+ including paths in tsconfig files, the usual solutions didn't always cut it. I had to install two VSCode extensions to resolve the issue:
steoates.autoimport and q.typescript-mono-repo-import-helper.