Closed
Description
TypeScript Version: 4.1.2
Search Terms: Object is possibly undefined
Code
function main(values: Array<string>) {
for (let i = 0; i < values.length; i++) {
if (typeof values[i] === 'string' && values[i].length > 0) {
console.log(i);
}
}
}
Expected behavior:
No error
Actual behavior:
TypeScript 4.1.2 reports a Object is possibly undefined
error in values[i].length
but given the first condition the object must be defined as it is of type 'string'
Related Issues: no