简体   繁体   中英

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. For instance, when I add OnInit using Path IntelliSense extension

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

在此处输入图片说明 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? (one of few reasons I am still resorting to use WebStorm over VSCode that is lighter & faster).

When your cursor is at the type you want to import, you can press + . (I guess on Windows it's Ctrl + . ).

This is possible with TypeScript 2.2. Before that, a lot of people used this extension: https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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