【问题标题】:Is there a keybinding in vscode for add import to an existing import statement or how to add imports on the fly in vscode?vscode 中是否有用于将导入添加到现有导入语句的键绑定,或者如何在 vscode 中动态添加导入?
【发布时间】:2017-08-19 16:45:40
【问题描述】:

似乎 VSCode 市场上的当前扩展无法正确添加角度导入。例如,当我使用 Path IntelliSense 扩展添加 OnInit 时

export class AppComponent implements OnInit

它从

导入它
import { OnInit } from '@angular/core/core'

代替

import { OnInit } from '@angular/core'

应该如此。我尝试浏览市场上的扩展,但没有找到任何远程可用的东西。但是我注意到 VSCode 提供了添加到现有导入语句的功能,您可以在此处的屏幕截图中看到该功能

有什么方法可以为此使用键绑定,而无需在出现黄色灯泡时单击它并手动选择它?和/或者您是否知道一个很棒的扩展,可以像 WebStorm 一样正确添加 Angular 导入? (我仍然使用 WebStorm 而不是更轻、更快的 VSCode 的几个原因之一)。

【问题讨论】:

    标签: angular typescript import visual-studio-code


    【解决方案1】:

    当您的光标位于您要导入的类型时,您可以按 ⌘+.(我猜在 Windows 上是 Ctrl+ .).

    TypeScript 2.2 可以做到这一点。在此之前,很多人都用过这个扩展:https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero

    【讨论】:

      猜你喜欢
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 2019-03-26
      • 2015-10-20
      • 1970-01-01
      • 2021-07-21
      相关资源
      最近更新 更多