Reputation: 20361
There is a new feature in TypeScript 2.8 that lets you "Organize imports": https://devblogs.microsoft.com/typescript/announcing-typescript-2-8-2/#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.
Upvotes: 81
Views: 85338
Reputation: 4875
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": "explicit"
}
}
Hopefully this can be helpful and good luck!
Upvotes: 90
Reputation: 41
In Visual Studio 2022 (might even be in previous releases too) the option Organize Imports
in the editor's code context menu has been renamed to Remove and Sort Usings
, which still does the same thing and also remains available using the shortcut CTRL+R followed by CTRL+G.
Just in case anyone overlooked it, as I did.
Upvotes: 4
Reputation: 20361
This feature has now been added to Visual Studio 2017.
One can invoke it the following ways:
Organize Imports
in the context menu.Upvotes: 26
Reputation: 1061
You can also use the following shortcut with your keyboard to "Organize imports":
Shift+Alt+O
Upvotes: 63
Reputation: 399
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
}
Upvotes: 38
Reputation: 107
This is a feature of Visual Studio Code and not Visual Studio 2017.
Upvotes: -1