Skip to content

Commit 0292c15

Browse files
author
Strift
committed
Fix typescript errors
1 parent 13f9729 commit 0292c15

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

packages/autocomplete-client/src/search/fetchMeilisearchResults.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
HITS_PER_PAGE,
99
} from '../constants'
1010
import { SearchClient as MeilisearchSearchClient } from '../types/SearchClient'
11+
import { HighlightResult } from 'instantsearch.js/es/types/algoliasearch'
1112

1213
interface SearchParams {
1314
/**
@@ -52,20 +53,20 @@ export function fetchMeilisearchResults<TRecord = Record<string, any>>({
5253
return response.results.map(
5354
(result: AlgoliaSearchResponse<TRecord>) => ({
5455
...result,
55-
hits: result.hits.map(
56-
(hit: AlgoliaSearchResponse<TRecord>['hits'][number]) => ({
57-
...hit,
58-
_highlightResult: hit._highlightResult
59-
? Object.entries(hit._highlightResult).reduce(
60-
(acc, [key, value]) => ({
61-
...acc,
62-
[key]: calculateHighlightMetadata(value.value),
63-
}),
64-
{}
65-
)
66-
: {},
67-
})
68-
),
56+
hits: result.hits.map((hit) => ({
57+
...hit,
58+
_highlightResult: (
59+
Object.entries(hit?._highlightResult || {}) as Array<
60+
[keyof TRecord, { value: string }]
61+
>
62+
).reduce(
63+
(acc, [field, highlightResult]) => ({
64+
...acc,
65+
[field]: calculateHighlightMetadata(highlightResult.value),
66+
}),
67+
{} as HighlightResult<TRecord>
68+
),
69+
})),
6970
})
7071
)
7172
}

0 commit comments

Comments
 (0)