Skip to content

Commit 2bf987e

Browse files
authoredAug 3, 2021
fix(types): fixing hits and results types in connectHits and connectInfiniteHits (#4820)
* fix(types): change results type to use Hit instead of AlgoliaHits The types Hit and AlgoliaHit are mostly the same. type Hit = { __position: number; __queryID?: string; } & AlgoliaHit; source: https://github.com/algolia/instantsearch.js/blob/21b6c53d4b1a3f3dd3a2375a5cfe0a31bef6ded6/src/types/results.ts#L60-L63 As of today, the hits exposed via results indeed [contain __position and __queryID](https://github.com/algolia/instantsearch.js/blob/21b6c53d4b1a3f3dd3a2375a5cfe0a31bef6ded6/src/connectors/hits/connectHits.ts#L158). * fix(types): add `hits` and `results` to `InfiniteHitsRenderState` While trying use `InfiniteHitsRenderState` in Angular InstantSearch I noticed how `hits` and `results` while being [part of the state expored by `connectInfiniteHits`](https://github.com/algolia/instantsearch.js/blob/master/src/connectors/infinite-hits/connectInfiniteHits.ts#L331-L342) are not actually visible on the type.
1 parent 21b6c53 commit 2bf987e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎src/connectors/hits/connectHits.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
Connector,
1717
Hits,
1818
Hit,
19-
AlgoliaHit,
2019
WidgetRenderState,
2120
} from '../../types';
2221
import { SearchResults } from 'algoliasearch-helper';
@@ -35,7 +34,7 @@ export type HitsRenderState = {
3534
/**
3635
* The response from the Algolia API.
3736
*/
38-
results?: SearchResults<AlgoliaHit>;
37+
results?: SearchResults<Hit>;
3938

4039
/**
4140
* Sends an event to the Insights middleware.

‎src/connectors/infinite-hits/connectInfiniteHits.ts

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
AlgoliaSearchHelper as Helper,
33
PlainSearchParameters,
44
SearchParameters,
5+
SearchResults,
56
} from 'algoliasearch-helper';
67
import {
78
Hits,
@@ -112,6 +113,16 @@ export type InfiniteHitsRenderState = {
112113
* Hits for the current page
113114
*/
114115
currentPageHits: Hits;
116+
117+
/**
118+
* Hits for current and cached pages
119+
*/
120+
hits: Hits;
121+
122+
/**
123+
* The response from the Algolia API.
124+
*/
125+
results?: SearchResults<Hit>;
115126
};
116127

117128
const withUsage = createDocumentationMessageGenerator({

0 commit comments

Comments
 (0)
Please sign in to comment.