typescript - ESLint 与 TypeScript,如何禁用严格的空检查?
问题描述
ESLint 抱怨我的对象可能为空,即使它周围有一个 if 语句。
const user: User | null = getUser()
if (user) { // if (user !== null) doesn't work either
await user.updateProfile({
displayName: this.displayName
})
}
有时它不会显示此错误,有时它会显示并且无法摆脱。所以我只想完全禁用这条规则,但我找不到规则名称。
这是 ESLint 中的什么规则名称,或者我还能如何关闭它?
解决方案
你试过这个吗?
const user: User | null = getUser()
if (user instanceof User) { // if (user !== null) doesn't work either
await user.updateProfile({
displayName: this.displayName
})
}
推荐阅读
- segmentation-fault - 使用 taosdump 工具时 TDengine 分段错误
- javascript - 如何在客户端使用 ajax $.post 向 Mongodb 插入数据?
- android-studio - 如何以最少的代码在单个活动/片段中添加带有搜索栏的多个音频
- php - PHP cURL 登录并循环访问停留在第一个 URL 上的 URL
- java - 通过遍历 MultiMap java 创建 DAG
- python - 使用 scipy 在 python 中进行快速傅立叶变换
- javascript - 如何清理导入Nodejs Mongodb socket io
- c# - 如何将 API 响应中的另一个模型列表关联到模型?
- go - 不同的 wg.Done() 导致 WaitGroup 在前一个 Wait 返回之前被重用
- java - Spring webflux中的异常处理