我一直有一个非常奇怪的Object is possibly 'undefined'错误。我的目标是这样的条件:
if (productPages?.length && productPages[productPages.length - 1].docs?.length < 10){...}
但条件productPages[productPages.length - 1].docs?.length < 10导致我出错Object is possibly 'undefined'。
问题是,如果我将<运算符更改为另一个,==或者===错误消失,对我来说,这似乎很奇怪。
我不想使用! - Non-null assertion operator,但我找不到任何其他解决方案。
测试的打字稿版本:3.7.3 和 4.0.5。
typescript ×1