简体   繁体   English

TSLint:警告:'no-use-before-declare'规则需要进行类型检查

[英]TSLint: Warning: The 'no-use-before-declare' rule requires type checking

I'm working on a medium sized Angular 4 project which uses TSLint. 我正在开发一个使用TSLint的中型Angular 4项目。

Every time I run the lint command with npm run lint (which uses ng lint ) I see a warning in the command line: 每次我用npm run lint (使用ng lint )运行lint命令时,我在命令行中看到一个警告:

Warning: The 'no-use-before-declare' rule requires type checking 警告:'no-use-before-declare'规则需要进行类型检查

I've tried to enable type-checking by adding the --type-check and --project path/to/the/tsconfig.json file which is apparently " all you need to do "™, but whatever I do, the warning is still shown in the console (as if the flags are not having any effect). 我试图通过将--type-check--project path/to/the/tsconfig.json文件来启用类型检查,这显然是“ 你需要做的全部 ”™,但无论我做什么,警告仍然显示在控制台中(好像标志没有任何效果)。

There are no lint issues in the project, regardless of whether I use the --type-check and --project flags or not. 无论我是否使用--type-check--project标志,项目中都没有lint问题。

Is type-checking being enabled? 是否启用了类型检查? Should the warning go away? 警告应该消失吗?

Edit 编辑

The problem is with passing the flags from the command-line to the ng lint command: 问题是将标志从命令行传递给ng lint命令:

If I run the command on the command line like this: 如果我在命令行上运行命令,如下所示:

npm run lint --type-check --project tsconfig.json

Then I still see the warning on the command line. 然后我仍然在命令行上看到警告。 If I update the command in the package.json to this: 如果我将package.json中的命令更新为:

"lint": "ng lint --type-check --project tsconfig.json",

Then the warning message is not shown in the console, and I get a couple of extra lints. 然后控制台中没有显示警告消息,我得到了几个额外的lints。

The problem was only with passing flags from command line to the ng lint command. 问题仅在于将命令行中的标志传递给ng lint命令。 I fixed it using this command from the command line: 我从命令行使用此命令修复它:

npm run lint -- --type-check

Just needed the extra -- to pass the flag through correctly 只需要额外--正确传递旗帜

A quick update to this answer: 快速更新此答案:

TSlint outputs now --type-check is deprecated. You only need --project to enable rules which need type information. 现在TSlint输出--type-check is deprecated. You only need --project to enable rules which need type information. --type-check is deprecated. You only need --project to enable rules which need type information. when using --type-check. 当使用--type-check时。

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

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