vscode typescript: 'Add all missing imports' shortcut

Viewed 27324

I am working on a typescript project (typescript3.x).

I recently noticed the Add all missing imports when I click on the bulb which comes when I am using more than one types which are not yet imported as shown below:

Is there a shortcut for the same? Or should I request it as a feature?

Thanks in advance

3 Answers

Is there a shortcut for the same?

Yes, coming in v1.46 (see v1.46 release notes: add missing imports source action):

Add all missing imports source action

VS Code has long supported a quick fix that adds all missing imports in a JavaScript or TypeScript file. This iteration, we introduced a new Add all missing imports source action lets you trigger this from anywhere in a file.

This also allows you to set up a keybinding for Add all missing imports:

{
    "key": "ctrl+shift+i",
    "command": "editor.action.sourceAction",
    "args": {
        "kind": "source.addMissingImports",
        "apply": "first"
    }
}

Or even enable Add all missing imports on save:

"editor.codeActionsOnSave": [
    "source.addMissingImports"
]

I think vscode now has this feature built in.

The shortcut Ctrl + . gives us options to autofix issues. I found this working even in case of multiple imports and all.

Please let me know if there is any other way to do the same :)

Assuming you mean a keyboard shortcut, I don't see the command listed at all in the "File" -> "Preferences" -> "Keyboard Shortcuts" window, so it appears there's no shortcut nor a way to configure one (as of Visual Studio Code 1.28.2). If the "Add all missing imports" code fix from the TypeScript extension is exposed as a command, then you would be able to assign a shortcut.

Related