I've been encountering a very peculiar issue with the error message Object is possibly 'undefined'
. My objective is to create a condition similar to this:
if (productPages?.length && productPages[productPages.length - 1].docs?.length < 10){...}
However, the condition
productPages[productPages.length - 1].docs?.length < 10
is causing the error Object is possibly 'undefined'
.
Interestingly, when I replace the <
operator with ==
or ===
, the error disappears, which strikes me as quite unusual.
I am reluctant to use the ! - Non-null assertion operator
, but currently, I cannot identify an alternative solution to resolve this issue.
Tested TypeScript versions: 3.7.3 and 4.0.5.