I've come across a peculiar issue in my TypeScript project (an Angular application). Here's the code snippet that's causing trouble:
const idx = myclone.findIndex(x => x.id === action.id);
const hasVal = idx>-1; // for some reason, Chrome debugger is skipping this line
if (idx>-1) { // despite idx===0, this condition always turns out to be false
myclone[idx].upload = action.status;
return {
...state,
ProgressFiles: myclone,
};
} else {
return state; // strangely enough, this block is executed even when idx > -1
}
It seems like there might be an issue with line 2 (which was added for debugging purposes) and line 3. However, I can't seem to pinpoint what exactly is wrong. The code appears to be correct to me, but the Chrome debugger is skipping over line 2 and incorrectly evaluating the if statement as false, despite idx being equal to 0. Any ideas on what could be going awry here?