Add stricter typing to dedup function

This commit is contained in:
SleeplessOne1917 2023-10-26 22:30:21 -04:00
parent 4a55278556
commit 548f00d59b

View file

@ -1,7 +1,7 @@
function dedupByProperty<T, R extends number | string | boolean>(
collection: T[],
keyFn: (obj: T) => R,
) {
function dedupByProperty<
T extends Record<string, any>,
R extends number | string | boolean,
>(collection: T[], keyFn: (obj: T) => R) {
return collection.reduce(
(acc, cur) => {
const key = keyFn(cur);