krisk / Fuse

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

Add key typings for Fuse expressions #684

Closed MariaSolOs closed 1 year ago

MariaSolOs commented 2 years ago

Description

It would be nice to have type information about the keys used for creating the Fuse instance when creating Fuse expressions.

As an example, say I have the following data set:

data = [
  {
    "title": "Old Man's War",
    "author": "John Scalzi"
  },
  {
    "title": "The Lock Artist",
    "author": "Steve"
  }
]

And I create the Fuse instance with const fuse = new Fuse(data, { keys: [ 'title' ] }). Then when writing fuse.search({ $or: [{ ;, I would like to have a completion suggestion for 'title' as my key for the $or clause.

Describe the solution you'd like

I imagine the solution being something like creating a temporary union literal type that corresponds to allowed keys for these logical query operators.

Describe alternatives you've considered

I guess one could maintain the typings independently from the Fuse implementation, but these would just add extra setup to maintain which could easily be integrated with this wonderful library.

MariaSolOs commented 2 years ago

I should also mention that if this sounds like a reasonable feature, I would love to work on it!

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