I've created a method called filterByFront
export const filterByFront = <T>(
value: string,
jsonData: T[],
setData: (data: T[]) => void,
filterKey: keyof T
) => {
const originData = jsonData;
if (!!value && !!value.trim()) {
setData(originData);
} else {
const filterData = originData.filter((item) => {
const newFilterValue = item[filterKey];
return newFilterValue
?.toLowerCase() //error message shows in this line
?.includes(value.trim().toLowerCase());
});
setData(filterData);
}
};
and I'm using it in components like this
<Input.Search
key="filter_role"
placeholder={t('common.filter')}
onSearch={(value) =>
filterByFront<IRoleListItem>(value, jsonData, setRoleData, 'id')
}
/>,
the type definition
export interface IRoleListItem {
authority?: string;
id?: string;
privilege?: string;
prohibit?: string;
tag_list?: string;
}
I encountered an error :
Property 'toLowerCase' does not exist on type 'NonNullable<T[keyof T]>'.ts(2339)
How can I resolve this error?