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:
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.importModuleSpecifier
andtypescript.preferences.importModuleSpecifier
settings specify the type of path to use for imports.Valid values are:
"relative"
to the file location."non-relative"
based on thebaseUrl
configured in yourjsconfig.json
/tsconfig.json
."auto"
to infer the shortest path type.These new preferences require TypeScript 2.9+.