How can I type the reduce function parameters.
interface IGroupArrayByKey<T> {
data: T[]
key: string
}
export const groupArrayByKey = <T>({ data, key }: IGroupArrayByKey<T>): object => {
return data.reduce((acc: any, item: any) => {
return { ...acc, [item[key]]: [...(acc[item[key]] || []), item] }
}, {})
}
groupArrayByKey function works on the principle that you provide the array as a date and key which the array should be grouped