You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Predicate types for partition (and other functions?) #1926
Lodash's partition accepts this, because it only requires that its callback returns an unknown. es-toolkit's partition rejects it, because it strictly requires that its callback returns a boolean.
After working with similar tradeoffs in my own projects, I prefer the unknown approach: There are many cases where making a decision based on whether a value is truthy or falsy (not just true or false) is a common and expected idiom, and I've found very few cases where strictly requiring a boolean prevents bugs. (The main one, I suppose, would be catching the scenario of mistakenly using an async function - i.e., accepting a function returning Promise<boolean> when it should be a boolean.) And, perhaps more importantly, accepting unknown is compatible with the TS definitions for JavaScript functions like Array.filter - intuitively, I would expect a utility toolkit's array functions to accept the same predicates as JavaScript's built-in array functions.
Could partition and similar be updated to accept unknown?
(I realize I could use es-toolkit/compat in these cases, but I'm hoping to not rely on compat long term.)
Activity