【问题标题】:unused expression, expected an assignment or function call Angular lint error in promise function未使用的表达式,期望赋值或函数调用 Promise 函数中的 Angular lint 错误
【发布时间】:2020-03-30 00:07:45
【问题描述】:

当我在 Angular 8 中运行 lint 命令时,lint 结果出现一些错误,例如

错误:未使用的表达式,需要赋值或函数调用

  new Promise((resolve) => {
  this.doclistCheck(data.cusType);
  resolve();
});

【问题讨论】:

    标签: angular eslint lint


    【解决方案1】:

    这是因为“no-unused-expression” tslint 规则。 试试这个,

      const _promise = new Promise((resolve) => {
        this.doclistCheck(data.cusType);
        resolve();
      });
    

    【讨论】:

    • 我得到了变量名必须在 lowerCamelCase、PascalCase 或 UPPER_CASE 中的错误。我在承诺之前删除下划线时解决了。完毕!谢谢!
    • 但现在我得到了另一个未使用变量的 tslint 错误。
    【解决方案2】:

    如果你使用它,你会得到类似的错误

    变量名必须为 lowerCamelCase、PascalCase 或 UPPER_CASE

    实际代码:

    const _promise = new Promise((resolve) => {
    this.doclistCheck(data.cusType);
    resolve();
    

    });

    更改为删除第一行中承诺前的下划线

    const promise = new Promise((resolve) => {
    this.doclistCheck(data.cusType);
    resolve();
    

    });

    【讨论】:

      猜你喜欢
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-10-21
      • 1970-01-01
      • 2015-11-03
      • 2020-03-21
      • 2011-05-09
      • 2014-12-26
      相关资源
      最近更新 更多