From 910afe3f5923e1bb39ad15b960a9d9770cc0b94b Mon Sep 17 00:00:00 2001 From: Stephen Haberman Date: Mon, 25 Nov 2024 08:32:38 -0600 Subject: [PATCH] fix: Simplify keyBy type. --- src/array/keyBy.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/array/keyBy.ts b/src/array/keyBy.ts index 7664c4d..53e726c 100644 --- a/src/array/keyBy.ts +++ b/src/array/keyBy.ts @@ -14,13 +14,11 @@ declare global { } } -Array.prototype.keyBy = function < - T, - K extends PropertyKey, - TK extends keyof T, - TKK extends T[TK] extends K ? TK : never, - Y = T, ->(this: T[], fnOrKey: CallbackFn | TKK, valueFn?: CallbackFn) { +Array.prototype.keyBy = function ( + this: T[], + fnOrKey: CallbackFn | keyof T[][number], + valueFn?: CallbackFn, +) { const result = {} as Record; const fn = typeof fnOrKey === "function" ? fnOrKey : (x: T) => x[fnOrKey] as K; this.forEach((e, i, a) => {