I check if array includes the value this way:
testArray.includes(value)
I need to do the same action if array is empty OR it includes the value. So I have this condition:
if (testArray == [] || testArray.includes(value)) {
// do something
}
But typescript
is trying to execute the second part of this condition even if testArray == []
. So I receive an error testArray.includes is underfined
.
I understand that I can fix it this way:
if (testArray == []) {
// do something
} else if (testArray.includes(value)) {
// do the same thing
}
But it doesn't look nice. Is there a way to put it in one if?
testArray
is an openapi query parameter, if it's important.