VS Code auto imports not using absolute paths and not indented

4.8k views Asked by At

enter image description here

I'm using Typescript with SvelteKit

When I type something that can be auto imported, as seen in the above GIF, the auto import doesn't keep things at the same indent level. I also need absolute paths:

/src/...

not

src/...

The VS code setting for this is called TypeScript > Suggest: Auto Imports

It's a minor inconvenience but I am a programmer and this is making me work harder than I ought to. /s

2

There are 2 answers

1
lilotop On

While I can't help with the exact solution,

I can propose a workaround that will save you some work.


Import Path:

  • Open the settings dialog (CTRL+,)
  • Search for typescript import module specifier
  • Make sure you select the TypeScript one, there's also one for JavaScript
  • Switch it from shortest to relative

enter image description here

Now when you auto-import, a relative path will be used which compiles correctly.


Indentation:

You can use ALT+SHIFT+F to format the entire file which will fix that as well.

0
Hari Doshi On

In your settings.json file add the following:

"javascript.preferences.importModuleSpecifier": "relative", "typescript.preferences.importModuleSpecifier": "relative"