Closed raviqqe closed 2 months ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
es-toolkit | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Aug 23, 2024 10:07am |
Hi, you're right about the suggestion. However, our current code convention is that functions selecting an element from an array shouldn't return undefined
. I'd like our library to return undefined
only when noUncheckedIndexedAccess is enabled. But, as far as I know, TypeScript doesn't allow reading compiler options directly.
@raon0211 I changed the implementation to guarantee that an array length is always more than zero. Can you take a look?
We can also allow both behaviour if it's preferrable:
export function minBy<T>(
items: readonly T[],
getValue: (element: T) => number
): typeof items extends [T, ...T[]] ? T : T | undefined {
// ...
}
What about we use function overloading as in head? It would be much readable.
It's ready for another review! 😄
Maybe, we should enable
noUncheckedIndexedAccess
compiler option for TypeScript too...