Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FuseSortFunctionItem typing is incorrect #788

Open
1 of 2 tasks
isaachinman opened this issue Dec 9, 2024 · 0 comments
Open
1 of 2 tasks

FuseSortFunctionItem typing is incorrect #788

isaachinman opened this issue Dec 9, 2024 · 0 comments
Labels

Comments

@isaachinman
Copy link

isaachinman commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Description of the bug

Just getting up and running with Fuse. It seems the type def for FuseSortFunctionItem is incorrect:

type FuseSortFunctionItem = {
  [key: string]: { $: string } | { $: string; idx: number }[]
}

If I log the output of sortFn: (a, b) => ..., I see:

{
  "idx": 84,
  "item": {
    "0": {
      "v": "todo-tf9oxpoi82b",
      "n": 1
    },
    "1": {
      "v": "2024-12-01T14:50:54.748Z",
      "n": 1
    }
  },
  "matches": [
    {
      "score": 0,
      "key": {
        "path": [
          "id"
        ],
        "id": "id",
        "weight": 0.5,
        "src": "id",
        "getFn": null
      },
      "value": "todo-tf9oxpoi82b",
      "norm": 1
    }
  ],
  "score": 1.4901161193847656e-8
}

So, FuseSortFunctionItem is neither [key: string]: { $: string }, nor { $: string; idx: number }[].

Note that I am on v7.0.0, which I cannot select in the GitHub issue template dropdown. That said, I see the exact same output if I rollback to v6.6.2.

Edit: I've found other occurrences of broken types now, as well. It seems the FuseIndex type itself is wrong – it is missing records, docs, norm, etc. I would be very happy to help improve the typing if you are open to PRs!

The Fuse.js version where this bug is happening.

6.6.2

Is this a regression?

  • This is a regression bug

Which version did this behavior use to work in?

None

Steps To Reproduce

const keys = [
  'id',
  {
    getFn: (todo: Todo) => todo.messages[0].date,
    name: 'date'
  }
]

const index = Fuse.createIndex<Todo>(keys, [])

const fuse = new Fuse<Todo>(
  [],
  {
    findAllMatches: true,
    keys,
    sortFn: (a, b) => {
      console.log({
        sortFnA: JSON.stringify(a),
      })
    },
    useExtendedSearch: true,
  },
  index,
)

Expected behavior

Correct types.

Screenshots

No response

Additional context

No response

@isaachinman isaachinman added the bug label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant