Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to configure vs code such way that import will use absolute path (not relative)?

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?

like image 873
karina Avatar asked Nov 16 '17 13:11

karina


People also ask

How do I change path VS code in terminal?

From the main menu, go to File > Preferences > Settings, and click on the “Open Settings (JSON)” icon shown below. Add a section, “terminal. integrated.

How do I set Vscode to default settings?

The easiest way to reset VS Code back to the default settings is to clear your user settings.json file. You can open the settings.json file with the Preferences: Open Settings (JSON) command in the Command Palette (Ctrl+Shift+P).


1 Answers

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 and typescript.preferences.importModuleSpecifier settings specify the type of path to use for imports.

Valid values are:

  • "relative" to the file location.
  • "non-relative" based on the baseUrl configured in your jsconfig.json / tsconfig.json.
  • "auto" to infer the shortest path type.

These new preferences require TypeScript 2.9+.

like image 110
mjolka Avatar answered Oct 29 '22 04:10

mjolka