Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vscode typescript: 'Add all missing imports' shortcut

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

like image 310
Leela Venkatesh K Avatar asked Oct 22 '18 09:10

Leela Venkatesh K


People also ask

What is Ctrl Shift P in VS Code?

You can define a keyboard shortcut for any task. From the Command Palette (Ctrl+Shift+P), select Preferences: Open Keyboard Shortcuts File, bind the desired shortcut to the workbench.

What does Ctrl d do in VS Code?

Ctrl+D selects the word at the cursor, or the next occurrence of the current selection. Tip: You can also add more cursors with Ctrl+Shift+L, which will add a selection at each occurrence of the current selected text.

How do I fix imports in VS Code?

Set the correct Python path in VSCode In order to fix Unresolved Import in VSCode, you have to set python. pythonPath key in the settings to the correct value. You can quickly open the settings. json editor by accessing File > Preferences or press Ctrl + , key combination.

How do I add Ctrl D code to Visual Studio?

The default shortcut is Alt + Shift + .


1 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" ]  or  "editor.codeActionsOnSave": {     "source.addMissingImports": true } 

"editor.codeActionsOnSave": [

like image 174
Mark Avatar answered Sep 16 '22 20:09

Mark