I'm currently working on a function that uses generic types to take two arguments (an array of objects and a search term), but I keep encountering an error - The property 'toLowerCase' is not available on the type 'T[keyof T]'
Here's the function:
function findMatchingTerms<T>(data: T[], searchTerm: string): T[] {
return data.filter((obj) => {
const filteredData = (Object.keys(obj) as Array<keyof typeof obj>).some((value) => {
return (
typeof obj[value] === "string" && obj[value].toLowerCase().includes(searchTerm.toLowerCase())
);
});
return filteredData;
});
}
What am I missing here?