【问题标题】:Unsafe member access .length on an `any` value & Unsafe member access .trim on an `any` value in AngularAngular 中“任何”值的不安全成员访问 .length 和“任何”值上的不安全成员访问 .trim
【发布时间】:2023-02-18 19:14:28
【问题描述】:

从下面的 if 条件中抛出错误,但代码仍按预期工作。

if ((item['id'].trim()).length !== 0) {
    return item;
}

错误 -

对“任意”值的不安全成员访问 .length。 eslint(@typescript-eslint/no-unsafe-member-access)

对“任何”值的不安全成员访问 .trim。 eslint(@typescript-eslint/no-unsafe-member-access)

【问题讨论】:

    标签: angular typescript eslint typescript-eslint


    【解决方案1】:

    解决方案 -

    if (((item['id'] as string).trim()).length !== 0) {
        return item;
    }
    

    【讨论】:

      猜你喜欢
      • 2020-11-04
      • 2021-12-23
      • 2023-02-18
      • 2013-05-26
      • 2021-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多