有没有办法从Angular 2+中删除未使用的导入和声明? [英] Is there a way to remove unused imports and declarations from Angular 2+?

查看:63
本文介绍了有没有办法从Angular 2+中删除未使用的导入和声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被分配去从最近已经离开公司的其他开发人员那里获取一些混乱的代码.

I'm assigned to take some messed code from other developers who have already left the company recently.

我很好奇地问,是否存在一些Visual Studio Code插件或其他手段可以帮助我们快速有效地整理和组织导入和引用?

I am curiously asking is there some plug-in of Visual Studio Code or other means that could help us to tidy and organize the imports and references quickly and effectively?

例如,也许有数百种这样的进口商品

For example, there are maybe hundreds of imports like this

import { AutoCompleteModule,InputSwitchModule } from 'primeng/primeng';
import { ListboxModule } from 'primeng/primeng';

可以类似地转换为

import { AutoCompleteModule,
         InputSwitchModule,
         ListboxModule  } from 'primeng/primeng';

或其他功能,例如 是否会自动从app.module或整个项目的所有组件中删除那些未使用的导入和声明?

Or other functions like automatically removing those unused imports and declarations from the app.module or from all components through the whole project?

感谢您的任何反馈!

推荐答案

编辑(如注释和其他人员的建议),Visual Studio Code已经发展并提供了内置的功能,作为命令组织导入",并且遵循默认键盘快捷键:

Edit (as suggested in comments and other people), Visual Studio Code has evolved and provides this functionality in-built as the command "Organize imports", with the following default keyboard shortcuts:

选项 + Shift + O

Alt + Shift + O (对于Windows)

Alt + Shift + O for Windows

原始答案:

我希望这个Visual Studio代码扩展可以满足您的需求: https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero

I hope this visual studio code extension will suffice your need: https://marketplace.visualstudio.com/items?itemName=rbbit.typescript-hero

它提供以下功能:

  • 将项目或库的导入添加到当前文件中
  • 在光标下为当前名称添加一个导入
  • 使用一个命令添加所有丢失的文件导入
  • 智能提示,提示符号并自动添加所需的导入 修复您编写的代码的灯泡功能"
  • 对进口商品进行排序和整理(对和删除未使用的商品进行排序和)
  • 打开的TS/TSX文档的代码大纲视图
  • JavaScript的所有很棒的东西! (不过,处于实验阶段,请在下面进行详细说明.)
  • Add imports of your project or libraries to your current file
  • Add an import for the current name under the cursor
  • Add all missing imports of a file with one command
  • Intellisense that suggests symbols and automatically adds the needed imports "Light bulb feature" that fixes code you wrote
  • Sort and organize your imports (sort and remove unused)
  • Code outline view of your open TS / TSX document
  • All the cool stuff for JavaScript as well! (experimental stage though, better description below.)

对于Mac:控件 + 选项 + o

For Mac: control+option+o

对于Win: Ctrl + Alt + o

For Win: Ctrl+Alt+o

这篇关于有没有办法从Angular 2+中删除未使用的导入和声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆