Skip to content

multiSearch function does not resolve the right type after passing a FederatedMultiSearchParams type in parameter #1767

@ldelhommeau

Description

@ldelhommeau

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:

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):
image

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.

Screenshots or Logs
image

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions