vscode 打字稿:'Add all missing imports' 快捷方式
vscode typescript: 'Add all missing imports' shortcut
我正在做一个打字稿项目 (typescript3.x)。
我最近注意到 Add all missing imports
当我使用多个尚未导入的类型时单击灯泡时出现,如下所示:
是否有相同的快捷方式?
还是我应该将其作为一项功能来请求?
提前致谢
假设您指的是键盘快捷键,我根本没有在 "File" -> "Preferences" -> "Keyboard Shortcuts" window 中看到命令,所以似乎没有捷径,也没有配置方法(从 Visual Studio 代码 1.28.2 开始)。如果来自 TypeScript 扩展的 "Add all missing imports" 代码修复作为命令公开,那么您将能够分配一个快捷方式。
我认为 vscode 现在内置了此功能。
快捷方式 Ctrl + . 为我们提供了自动修复问题的选项。我发现即使在多次导入和全部导入的情况下也能正常工作。
如果有任何其他方法可以做到这一点,请告诉我:)
Is there a shortcut for the same?
是的,将在 v1.46 中推出(请参阅 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"
]
我正在做一个打字稿项目 (typescript3.x)。
我最近注意到 Add all missing imports
当我使用多个尚未导入的类型时单击灯泡时出现,如下所示:
是否有相同的快捷方式? 还是我应该将其作为一项功能来请求?
提前致谢
假设您指的是键盘快捷键,我根本没有在 "File" -> "Preferences" -> "Keyboard Shortcuts" window 中看到命令,所以似乎没有捷径,也没有配置方法(从 Visual Studio 代码 1.28.2 开始)。如果来自 TypeScript 扩展的 "Add all missing imports" 代码修复作为命令公开,那么您将能够分配一个快捷方式。
我认为 vscode 现在内置了此功能。
快捷方式 Ctrl + . 为我们提供了自动修复问题的选项。我发现即使在多次导入和全部导入的情况下也能正常工作。
如果有任何其他方法可以做到这一点,请告诉我:)
Is there a shortcut for the same?
是的,将在 v1.46 中推出(请参阅 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" ]