I have a helper function that removes duplicates from array
export const removeDublicatesFromArray = (
array: IRegulations[],
key: string
) => {
return [
...new Map(array.map((item: IRegulations) => [item[key], item])).values(),
]
}
And TS gives me an error on [item[key].
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'IRegulations'.
No index signature with a parameter of type 'string' was found on type 'IRegulations'
I did a research and fixed this error passing
Record<string, string>[] instead of IRegulations[] but it broke the code where this function is used.
Any way I can handle this error with these types?