【发布时间】:2019-05-12 08:55:15
【问题描述】:
我使用 ionic 生成了一个 ionic 4 项目:ionic start app sidemenu --type=angular。
我现在想让 linting 规则更加严格,并引入了'no-any'。
但不幸的是,linting 失败了。
它给了我:
$ 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 中查找它。
但是,我找不到它被声明为there
我该如何解决这个问题?
【问题讨论】:
标签: typescript webpack tslint ionic4