【问题标题】:TSLint: Warning: The 'no-use-before-declare' rule requires type checkingTSLint:警告:'no-use-before-declare' 规则需要类型检查
【发布时间】:2018-02-26 16:36:51
【问题描述】:

我正在开发一个使用 TSLint 的中型 Angular 4 项目。

每次我使用npm run lint(使用ng lint)运行lint 命令时,我都会在命令行中看到一条警告:

警告:“no-use-before-declare”规则需要类型检查

我尝试通过添加 --type-check--project path/to/the/tsconfig.json 文件来启用类型检查,这显然是“你需要做的一切”™,但无论我做什么,警告都是仍然显示在控制台中(好像标志没有任何效果)。

无论我是否使用 --type-check--project 标志,项目中都没有 lint 问题。

是否启用了类型检查?警告应该消失吗?

编辑

问题在于将标志从命令行传递到ng lint 命令:

如果我像这样在命令行上运行命令:

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

然后我仍然在命令行上看到警告。如果我将 package.json 中的命令更新为:

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

然后警告消息显示在控制台中,我得到了一些额外的 lints。

【问题讨论】:

  • ng lint --type-check 对我来说适用于需要类型检查的规则。你用的是什么版本的@angular/cli
  • 我使用的是 1.3.1 版
  • 啊,问题在于将标志传递给命令,我将更新问题...

标签: angular typescript tslint


【解决方案1】:

对此答案的快速更新:

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

【讨论】:

    【解决方案2】:

    问题仅在于将标志从命令行传递给ng lint 命令。我从命令行使用此命令修复了它:

    npm run lint -- --type-check
    

    只需要额外的-- 来正确传递标志

    【讨论】:

      猜你喜欢
      • 2018-03-24
      • 2020-03-23
      • 2017-09-11
      • 1970-01-01
      • 2021-12-30
      • 2021-06-25
      • 2019-05-12
      • 1970-01-01
      • 2019-03-06
      相关资源
      最近更新 更多