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

查看:26
本文介绍了有没有办法从 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:

option+Shift+O for Mac

Alt + Shift + O Windows

Alt + Shift + O for Windows

原答案:

我希望这个 Visual Studio 代码扩展能够满足您的需求:https://market.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 的所有很酷的东西!(不过是实验阶段,下面有更好的描述.)

对于 Mac:control+option+o

对于 Win:Ctrl+Alt+o

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

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