简体   繁体   English

如何在 Angular 中为未使用的导入禁用 tslint

[英]How to disable tslint for an unused import in Angular

I've a small project.我有一个小项目。 I wanted to create a production built for the same.我想创建一个为此而构建的产品。 I used this command:我使用了这个命令:

ng build --prod

But it was throwing some build errors.但它抛出了一些构建错误。 So I asked my tech lead and she told me add this import:所以我问了我的技术负责人,她告诉我添加这个导入:

import ResizeObserver from 'resize-observer-polyfill'

The build was successful after this but now the files are not passing linting test.在此之后构建成功,但现在文件没有通过 linting 测试。 Since the import is not used anywhere else in this code.由于导入未在此代码中的其他任何地方使用。 I'm getting this error:我收到此错误:

ERROR: C:/Users/320035648/Angular/pinc-insights-ui/src/app/app.module.ts:29:1 - All imports on this line are unused.错误:C:/Users/320035648/Angular/pinc-insights-ui/src/app/app.module.ts:29:1 - 此行上的所有导入均未使用。 Lint errors found in the listed files.在列出的文件中发现 Lint 错误。

So I added this line before the import:所以我在导入之前添加了这一行:

/* tslint: disable: no-unused-variable */

But still I'm getting same error.但我仍然遇到同样的错误。 Please help me.请帮我。

如果您不使用ResizeObserver ,因此只使用库导入副作用,为什么不简单地以这种方式导入库:

import 'resize-observer-polyfill'

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

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