简体   繁体   English

在vscode中是否存在用于向现有import语句添加导入的键绑定,或者如何在vscode中动态添加导入?

[英]Is there a keybinding in vscode for add import to an existing import statement or how to add imports on the fly in vscode?

Seems like current extensions on VSCode marketplace can not properly add angular imports. 似乎VSCode市场上的当前扩展无法正确添加角度导入。 For instance, when I add OnInit using Path IntelliSense extension 例如,当我使用Path IntelliSense扩展名添加OnInit时

export class AppComponent implements OnInit

It imports it from 它从进口

import { OnInit } from '@angular/core/core'

Instead of 代替

import { OnInit } from '@angular/core'

As it should. 正如它应该。 I tried looking through extensions on the marketplace but failed to find anything remotely workable. 我尝试浏览市场上的扩展程序,但找不到任何远程可行的方法。 I noticed however that VSCode provides a functionality to add to an existing import statement which you can see in the screenshot here 但是我注意到VSCode提供了添加到现有import语句中的功能,您可以在此处的屏幕截图中看到该功能。

在此处输入图片说明 Is there any way to use a keybinding for this without the need to click a yellow light bulb when it appears and manually selecting it? 有什么方法可以使用快捷键绑定,而无需在出现时单击黄色灯泡并手动选择它? And/Or do you perhaps know a great extension that adds Angular imports correctly like WebStorm does? 和/或/或者您是否知道一个很好的扩展,可以像WebStorm一样正确添加Angular导入? (one of few reasons I am still resorting to use WebStorm over VSCode that is lighter & faster). (我仍然选择通过更轻巧,更快的VSCode使用WebStorm的几个原因之一)。

When your cursor is at the type you want to import, you can press + . 当光标位于要导入的类型时,可以按 + (I guess on Windows it's Ctrl + . ). (我猜在Windows上是Ctrl + )。

This is possible with TypeScript 2.2. 使用TypeScript 2.2可以做到这一点。 Before that, a lot of people used this extension: https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero 在此之前,很多人都使用此扩展名: https : //marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM