From b5dfa452a8a12b25a34c1d2299740f3b71c69500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Tue, 9 Jul 2024 12:35:42 +0200 Subject: [PATCH] fix: "FuseSortFunctionMatch" key is not a string --- dist/fuse.d.ts | 28 ++++++++++++++++++---------- src/index.d.ts | 26 +++++++++++++++++--------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/dist/fuse.d.ts b/dist/fuse.d.ts index 4abfb90da..0f8c366e1 100644 --- a/dist/fuse.d.ts +++ b/dist/fuse.d.ts @@ -153,13 +153,21 @@ type FuseSortFunctionItem = { * } * ``` */ -type FuseSortFunctionMatch = { +type FuseSortFunctionMatch = { score: number - key: string + key: FuseSortFunctionMatchKey value: string indices: ReadonlyArray[] } +interface FuseSortFunctionMatchKey { + id: string + getFn?: FuseGetFunction + path: string[] + src: string + weight: number +} + /** * @example * ```ts @@ -172,20 +180,20 @@ type FuseSortFunctionMatch = { * } * ``` */ -type FuseSortFunctionMatchList = FuseSortFunctionMatch & { +type FuseSortFunctionMatchList = FuseSortFunctionMatch & { idx: number } -type FuseSortFunctionArg = { +type FuseSortFunctionArg = { idx: number item: FuseSortFunctionItem score: number - matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[] + matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[] } -type FuseSortFunction = ( - a: FuseSortFunctionArg, - b: FuseSortFunctionArg +type FuseSortFunction = ( + a: FuseSortFunctionArg, + b: FuseSortFunctionArg ) => number /** @@ -317,7 +325,7 @@ interface IFuseOptions { /** Whether to sort the result list, by score. */ shouldSort?: boolean /** The function to use to sort all the results. The default will sort by ascending relevance score, ascending index. */ - sortFn?: FuseSortFunction + sortFn?: FuseSortFunction /** At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. */ threshold?: number /** When `true`, it enables the use of unix-like search commands. See [example](/examples.html#extended-search). */ @@ -365,4 +373,4 @@ type Expression = | { $and?: Expression[] } | { $or?: Expression[] } -export { Expression, FuseGetFunction, FuseIndex, FuseIndexObjectRecord, FuseIndexOptions, FuseIndexRecords, FuseIndexStringRecord, FuseOptionKey, FuseOptionKeyObject, FuseResult, FuseResultMatch, FuseSearchOptions, FuseSortFunction, FuseSortFunctionArg, FuseSortFunctionItem, FuseSortFunctionMatch, FuseSortFunctionMatchList, IFuseOptions, RangeTuple, RecordEntry, RecordEntryArrayItem, RecordEntryObject, Fuse as default }; +export { Expression, FuseGetFunction, FuseIndex, FuseIndexObjectRecord, FuseIndexOptions, FuseIndexRecords, FuseIndexStringRecord, FuseOptionKey, FuseOptionKeyObject, FuseResult, FuseResultMatch, FuseSearchOptions, FuseSortFunction, FuseSortFunctionArg, FuseSortFunctionItem, FuseSortFunctionMatch, FuseSortFunctionMatchKey, FuseSortFunctionMatchList, IFuseOptions, RangeTuple, RecordEntry, RecordEntryArrayItem, RecordEntryObject, Fuse as default }; diff --git a/src/index.d.ts b/src/index.d.ts index a039a8307..282084e78 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -153,13 +153,21 @@ export type FuseSortFunctionItem = { * } * ``` */ -export type FuseSortFunctionMatch = { +export type FuseSortFunctionMatch = { score: number - key: string + key: FuseSortFunctionMatchKey value: string indices: ReadonlyArray[] } +export interface FuseSortFunctionMatchKey { + id: string + getFn?: FuseGetFunction + path: string[] + src: string + weight: number +} + /** * @example * ```ts @@ -172,20 +180,20 @@ export type FuseSortFunctionMatch = { * } * ``` */ -export type FuseSortFunctionMatchList = FuseSortFunctionMatch & { +export type FuseSortFunctionMatchList = FuseSortFunctionMatch & { idx: number } -export type FuseSortFunctionArg = { +export type FuseSortFunctionArg = { idx: number item: FuseSortFunctionItem score: number - matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[] + matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[] } -export type FuseSortFunction = ( - a: FuseSortFunctionArg, - b: FuseSortFunctionArg +export type FuseSortFunction = ( + a: FuseSortFunctionArg, + b: FuseSortFunctionArg ) => number /** @@ -317,7 +325,7 @@ export interface IFuseOptions { /** Whether to sort the result list, by score. */ shouldSort?: boolean /** The function to use to sort all the results. The default will sort by ascending relevance score, ascending index. */ - sortFn?: FuseSortFunction + sortFn?: FuseSortFunction /** At what point does the match algorithm give up. A threshold of `0.0` requires a perfect match (of both letters and location), a threshold of `1.0` would match anything. */ threshold?: number /** When `true`, it enables the use of unix-like search commands. See [example](/examples.html#extended-search). */