I have a code snippet that calculates the intersection of multiple arrays of strings.
export const findIntersection = (list1: string[], list2: string[], ...otherLists): string[] => {
const result = [];
for (let i = 0; i < list1.length; i++) {
const item1 = list1[i];
let found = false;
for (let j = 0; j < list2.length && !found; j++) {
found = item1 === list2[j];
}
if (found === true) {
result.push(item1);
}
}
if (otherLists.length) {
return findIntersection(result, otherLists.shift(), ...otherLists);
} else {
return result;
}
};
While this function works well in JS, I am facing some challenges while converting it to Typescript. Specifically, I'm struggling with typing the ...otherLists
parameters.
The error message I'm receiving is as follows: