ReviewOS

stacks/ts-collect

`contains` doesn't actually accept a callback

#37
Open mjsarfatti opened this 8 days ago ·
8 days ago

Describe the bug

The docs state that a callback can be passed to contains, but that's not the case, and the types in fact reflect this.

Relevant code:

    contains(keyOrItem: T | keyof T | undefined, value?: any): boolean {
      if (arguments.length === 1) {
        if (keyOrItem === undefined)
          return false
        return collection.items.includes(keyOrItem as T)
      }
      return collection.items.some(item => item[keyOrItem as keyof T] === value)
    },

One solution is to edit the docs and remove references to the callback function. A better solution might be to implement this (see, for example, how collect.js does it)

Reproduction

https://I-dont-believe-its-needed.com

System Info

Not needed

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
8 days ago

Has anyone managed to take a look at this? Happy to contribute a PR based on feedback!

Sign in to comment on this issue.