I've developed a unique class with two properties that store arrays of tuples containing numbers. Additionally, I've implemented a method called "getIndex" which dynamically accesses these properties and checks for duplicate number values within the tuples. Here's the function in question:
getIndex(posX: number, posY: number, pathArr: string) {
for (let routeCoordinates of this[pathArr]) {
if (routeCoordinates[0] === posX && routeCoordinates[1] === posY) {
return this[pathArr].indexOf(routeCoordinates);
}
}
}
The issue arises when attempting to pass pathArr as a key, resulting in the following error message:
"Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathfinderSecondStage'. No index signature with a parameter of type 'string' was found on type 'PathfinderSecondStage'."
I'm aware of generics, but the solutions I've come across online don't seem to work well with instances of classes. Is there any way to solve this while maintaining type checking?