From 36043bb11e64adc7d887c3ea1a8ea14e3e6413e0 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 16 Aug 2023 14:47:29 -0400 Subject: [PATCH] fix: types --- src/useMatches.tsx | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/useMatches.tsx b/src/useMatches.tsx index 16f7fb8..7423fe8 100644 --- a/src/useMatches.tsx +++ b/src/useMatches.tsx @@ -75,16 +75,18 @@ export function useMatches() { }, [getDeepResults, rootResults, emptySearch]); const fuseOptions = { - keys: [{ - name: "name", - weight: 0.5 - }, - { - name: "keywords", - getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually - weight: 0.5 - }, - "subtitle"], + keys: [ + { + name: "name", + weight: 0.5, + }, + { + name: "keywords", + getFn: (item) => item.keywords.split(","), // make keyword an array. so fuse can look through words individually + weight: 0.5, + }, + "subtitle", + ], includeScore: true, includeMatches: true, threshold: 0.2, @@ -190,7 +192,11 @@ type Match = { score: number; }; -function useInternalMatches(filtered: ActionImpl[], search: string, fuse: Fuse) { +function useInternalMatches( + filtered: ActionImpl[], + search: string, + fuse: Fuse +) { const value = React.useMemo( () => ({ filtered, @@ -212,12 +218,12 @@ function useInternalMatches(filtered: ActionImpl[], search: string, fuse: Fuse ({ - score: 1 / (score + 1), // Convert the Fuse score to the format used in the original code + score: 1 / ((score ?? 0) + 1), // Convert the Fuse score to the format used in the original code action, })); return matches; - }, [throttledFiltered, throttledSearch]) as Match[]; + }, [throttledFiltered, throttledSearch, fuse]) as Match[]; } /**