【问题标题】:ESLint with TypeScript, how to disable the strict null check?ESLint 与 TypeScript,如何禁用严格的空检查?
【发布时间】:2020-04-05 03:54:21
【问题描述】:

ESLint 抱怨我的对象可能为 null,即使它周围有 if 语句。

     const user: User | null = getUser()

      if (user) { //  if (user !== null) doesn't work either
        await user.updateProfile({
          displayName: this.displayName
        })
      }

有时它不会显示此错误,有时它会显示并且无法摆脱。所以我只想完全禁用此规则,但我找不到规则名称。

这是 ESLint 中的什么规则名称,或者我该如何关闭它?

【问题讨论】:

  • 确切的 linter 错误信息是什么?一个可重复的样本会很有帮助。

标签: typescript eslint


【解决方案1】:

你试过了吗?

const user: User | null = getUser()

      if (user instanceof User) { //  if (user !== null) doesn't work either
        await user.updateProfile({
          displayName: this.displayName
        })
      }

【讨论】:

    猜你喜欢
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 2019-03-23
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2016-06-06
    • 2017-01-06
    相关资源
    最近更新 更多