Fuse icon indicating copy to clipboard operation
Fuse copied to clipboard

Wrong `key` type for `FuseSortFunctionMatch` type

Open ryangoree opened this issue 2 months ago • 0 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Description of the bug

The sortFn option's arguments are typed as FuseSortFunctionArg:

https://github.com/krisk/Fuse/blob/fac16735655bedbee434a19855cdfc4a1dded5ac/src/index.d.ts#L325

https://github.com/krisk/Fuse/blob/fac16735655bedbee434a19855cdfc4a1dded5ac/src/index.d.ts#L182-L192

The type uses a string for the matches?.[idx]?.key property:

https://github.com/krisk/Fuse/blob/fac16735655bedbee434a19855cdfc4a1dded5ac/src/index.d.ts#L159-L164

However, the actual type is an object created with the createKey function:

https://github.com/krisk/Fuse/blob/fac16735655bedbee434a19855cdfc4a1dded5ac/src/tools/KeyStore.js#L38-L71

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

  1. Run the following and observe that the logged key is an object:
const fuse = new Fuse(
  [
    { name: "test 1", id: "123" },
    { name: "test 2", id: "456" },
  ],
  {
    keys: ["name", "id"],
    includeMatches: true,
    sortFn: (a, b) => {
      console.log("key:", a.matches?.[0]?.key);
      return a.score - b.score;
    },
  }
);

fuse.search("test");
key: {path: Array(1), id: 'name', weight: 1, src: 'name', getFn: null}

Expected behavior

The key property on FuseSortFunctionMatch should be typed as an object based on the return type of createKey.

Screenshots

No response

Additional context

[!IMPORTANT] The version selector in this issue template only lets me select up to version 6.6.2, but this was observed in version 7.1.0.

ryangoree avatar Dec 12 '25 19:12 ryangoree