我使用离子生成了一个离子4项目:ionic start app sidemenu --type=angular
。 我现在想让棉绒规则更严格,引入'no-any'
. 但不幸的是,棉绒失败了。 它给了我:
$ ng lint app
Linting "app"...
ERROR: ./src/test.ts[10, 24]: Type declaration of 'any' loses type-safety. Consider replacing it with a more precise type.
Lint errors found in the listed files.
问题是这一行:
declare const require: any;
在此文件中:
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /.spec.ts$/);
// And load the modules.
context.keys().map(context);
我怀疑require
是由 webpack 提供的。 如果我理解正确,它应该在@types/webpack/index.d.ts
中声明,并且我必须从webpack
中包含它,这反过来又会在@types
中查找它。 但是,我找不到它在那里声明
如何解决此问题?
require
是CommonJS(CJS)模块系统的一部分。require
的键入可以在@types/node
或@types/webpack-env
包中找到。从 npm 安装其中一个:
npm install --save-dev @types/node