如何消除Angular 18.2.0中未使用导入数组的(-998113)警告
关闭Angular 18.2.0中“Imports array contains unused imports(-998113)”警告的方案
你可以通过以下全局配置方式屏蔽该警告,无需逐个删除未使用的导入:
1. 修改项目根目录的tsconfig.json
在配置文件中添加angularCompilerOptions,将警告代码998113加入到suppressWarnings数组中,全局禁用该警告:
{ "compilerOptions": { // 保留原有编译配置... }, "angularCompilerOptions": { "suppressWarnings": [ "998113" ] } }
修改后重启开发服务或重新构建项目,警告即可消失。
2. 修改angular.json中的构建/服务配置
如果只想在构建或开发服务过程中屏蔽警告,可以在对应命令的配置里添加suppressWarnings:
"projects": { "你的项目名称": { "architect": { "build": { "options": { // 原有构建配置... "suppressWarnings": ["998113"] } }, "serve": { "options": { "buildTarget": "你的项目名称:build", "suppressWarnings": ["998113"] } } } } }
单个组件临时屏蔽(可选)
如果仅需在特定组件中屏蔽该警告,可在组件装饰器上方添加注释:
// @ts-ignore: 998113 @Component({ selector: 'app-your-component', imports: [UnusedImport], templateUrl: './your-component.html' })
内容的提问来源于stack exchange,提问作者TheCuBeMan
相关产品推荐
相关产品推荐

