There is a new feature in TypeScript 2.8 that lets you "Organize imports": https://blogs.msdn.microsoft.com/typescript/2018/03/27/announcing-typescript-2-8/#organize-imports
Basically it does the following:
The page shows that the feature can be invoked in Visual Studio Code with the Shift+Alt+O keyboard shortcut. Does anybody know how this feature can be invoked in Visual Studio (2017)?
UPDATE:
From version 15.8 onward Visual Studio 2017 highlights unused imports by greying them out.
To sort manually, you will need to open the Command Palette ( Ctrl+Shift+P or ⌘+Shift+P ) and find the Sort Imports command. That command can also be used with any custom keybinding ( Ctrl+Shift+O or ⌘+Shift+O are the default).
In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON. Et voilà! Your imports will now be organized every time you save a file.
Visual Studio Code has released a new feature in April last year which enable to organize imports on save. Can you try to update your current settings.json
with the following changes:
"editor.formatOnSave": true,
"[typescript]": {
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
Hopefully this can be helpful and good luck!
You can also use the following shortcut with your keyboard to "Organize imports":
Shift+Alt+O
A slightly modified version of JayKan's answer but this worked for me in VSCode settings.json.
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
This feature has now been added to Visual Studio 2017.
One can invoke it the following ways:
Organize Imports
in the context menu.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With