I am facing an issue with the following code:
First, I retrieve the ID parameter from the URL:
editUserId = this.route.snapshot.paramMap.get('id');
Next, I use FindIndex on an array of objects to find the index of an element that matches the above mentioned ID fetched from the URL:
this.userToUpdate = this.allUsers.findIndex((x: any) => x.UserId === this.editUserId);
(this.allUsers) is the array of objects in question.
Despite my efforts, the FindIndex method always returns -1. I have attempted two different approaches, but both result in the same error message: "This condition will always return 'false' since the types 'number' and 'string | null' have no overlap":
this.userToUpdate = this.allUsers.findIndex((x: any) => parseInt(x.UserId) === this.editUserId);
this.userToUpdate = this.allUsers.findIndex((x: any) => Number(x.UserId) === this.editUserId);
Any insights into what might be causing this issue?