krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.76k stars 753 forks source link

[Typings] Incorrect `readonly` annotations #677

Closed artemiswkearney closed 1 year ago

artemiswkearney commented 1 year ago

Describe the bug

The Typescript typings for Fuse claim that the constructor argument for the initial collection (possibly other arguments elsewhere in the API) takes a ReadonlyArray, but the add, remove, and removeAt methods modify the array, which isn't legal with a ReadonlyArray

Version

v6.6.2

Is this a regression?

No

🔬Minimal Reproduction

  1. Create an array with some documents in it.
  2. Put a reference to that array in a variable of type ReadonlyArray<T> or readonly T[], guaranteeing to the type system that that reference can't be used to modify the array.
  3. Construct a Fuse instance from that variable.
  4. Modify the Fuse instance's collection by calling the add, remove, and/or removeAt methods.
  5. The original array has now been modified through what was supposed to be a readonly reference.

Additional context

https://www.typescriptlang.org/docs/handbook/2/objects.html#the-readonlyarray-type

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 120 days with no activity. Remove stale label or comment or this will be closed in 30 days

artemiswkearney commented 1 year ago

This is still the case