-
Notifications
You must be signed in to change notification settings - Fork 99
Description
Description
I just updated the Meilisearch Javascript SDK to 0.45 to use the new multiSearch
function with the mergeFacets
attribute.
I have strongly typed my parameter to be of type FederatedMultiSearchParams
as written in the SDK definition:
meilisearch-js/src/meilisearch.ts
Lines 217 to 232 in 74aa48c
multiSearch<T extends Record<string, unknown> = Record<string, any>>( | |
queries: MultiSearchParams, | |
config?: Partial<Request>, | |
): Promise<MultiSearchResponse<T>>; | |
multiSearch<T extends Record<string, unknown> = Record<string, any>>( | |
queries: FederatedMultiSearchParams, | |
config?: Partial<Request>, | |
): Promise<SearchResponse<T>>; | |
async multiSearch<T extends Record<string, unknown> = Record<string, any>>( | |
queries: MultiSearchParams | FederatedMultiSearchParams, | |
config?: Partial<Request>, | |
): Promise<MultiSearchResponse<T> | SearchResponse<T>> { | |
const url = `multi-search`; | |
return await this.httpRequest.post(url, queries, undefined, config); | |
} |
But the return type of the function is always of type MultiSearchResponse<Record<string, any>>
were I was expecting Promise<SearchResponse<T>>
.
Important note: I tried using this hack to check what was the returned object's type at runtime:
const searchResults = (await this.meilisearchClient().multiSearch(multiSearchArgs)) as unknown as SearchResponse;
And the object is of type SearchResponse
with the correct properties at the root level of the object (estimatedTotalHits
and facetDistribution
):
Expected behavior
When calling the multiSearch
function with the parameter queries
of type FederatedMultiSearchParams
I expect to have a response of type SearchResponse
.
Current behavior
The TS resolution shows that the return type is MultiSearchResponse
.
Environment (please complete the following information):
- OS: MacOS Sonoma Apple M1 Pro
- Meilisearch version: Meilisearch v1.11.3 (from docker image
getmeili/meilisearch:v1.11
) - meilisearch-js version: v0.45 (from my package.json
"meilisearch": "^0.45.0",
) - Browser: No brower, the process is run via a Strapi backend v4.15.5 (nodejs)