Skip to content

Conversation

@ssi02014
Copy link
Contributor

@ssi02014 ssi02014 commented Jul 1, 2025

In my opinion, given the use case of the pull function, the type of valuesToRemove could be defined with a clearer type than unknown.

For example, it is unlikely that you will ever want to remove an element that is completely separate from the arr array element type, as shown below.

const arr = [1, 2, 3, 4, 5]; 
// number[]
const valuesToRemove = [1, true, 'str']; 
// (string | number | boolean)[]

pull(arr, valuesToRemove); // ❌, I think of these use cases as edge cases.

Since unknown is a broad type, why not improve the developer experience by improving the type of valuesToRemove?
It would be nice to catch type errors in advance.

const arr = [1, 2, 3, 4, 5]; 
// number[]
const valuesToRemove = [1, true, 'str']; 
// (string | number | boolean)[]

pull(arr, valuesToRemove); 
// TypeError, Arguments of the form '(string | number | boolean)[]' cannot be assigned to parameters of the form 'readonly number[]'.

I was thinking that for compat/pull, it would be better to match the type of lodash for compatibility with lodash.
However, values in the compat/pull function can also set the type more narrowly.

interface LoDashStatic {
    /**
     * Removes all provided values from array using SameValueZero for equality comparisons.
     *
     * Note: Unlike _.without, this method mutates array.
     *
     * @param array The array to modify.
     * @param values The values to remove.
     * @return Returns array.
     */
    pull<T>(array: T[], ...values: T[]): T[];
    /**
     * @see _.pull
     */
    pull<T>(array: List<T>, ...values: T[]): List<T>;
}
interface Collection<T> {
    /**
     * @see _.pull
     */
    pull(...values: T[]): Collection<T>;
}
interface CollectionChain<T> {
    /**
     * @see _.pull
     */
    pull(...values: T[]): CollectionChain<T>;
}

The test code and existing logic is largely unchanged.
If you have additional ideas and feedback, we'd love to hear them.

@vercel
Copy link

vercel bot commented Jul 1, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
es-toolkit Ready Ready Preview Comment Sep 9, 2025 2:40pm

@codecov-commenter
Copy link

codecov-commenter commented Jul 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (2f40871) to head (e79f3bb).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1242   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files         468      468           
  Lines        4439     4439           
  Branches     1309     1309           
=======================================
  Hits         4428     4428           
  Misses         11       11           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


bench('es-toolkit/pull', () => {
pullToolkit([...array], even);
pullToolkit([...array], ...even);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a type error, which I fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants