簡體   English   中英

如何使用“無限制” tslint規則使用webpack require?

[英]How to use webpack require with 'no-any' tslint rule?

我使用ionic生成了ionic 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)模塊系統的一部分。 @types/node@types/webpack-env包中可以找到require@types/node 從npm安裝其中之一:

npm install --save-dev @types/node

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM