-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiSearch function does not resolve the right type after passing a FederatedMultiSearchParams type in parameter #1767
Comments
It seems the TS typechecker is not able to infer the return type properly just by the type of the searchparameters. I think creating conditional type could solve this issue. export type MultiSearchResponseOrSearchResponse<
T1 extends FederatedMultiSearchParams | MultiSearchParams,
T2 extends Record<string, unknown> = Record<string, any>,
> = T1 extends FederatedMultiSearchParams
? SearchResponse<T2>
: MultiSearchResponse<T2>; @flevi29 what do you think? |
I think this: #1776 should fix it |
Reopened for the following reason: #1689 (comment) |
It seems that if you don't pass the arguments directly into the function as they are, TS doesn't even try to infer from it, which feels like a bug to me. There's no nice solution here, the result will have to be casted, which honestly is pretty much what you'd be doing with generics either way, and not a lot more verbose. |
Description
I just updated the Meilisearch Javascript SDK to 0.45 to use the new
multiSearch
function with themergeFacets
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
But the return type of the function is always of type
MultiSearchResponse<Record<string, any>>
were I was expectingPromise<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
andfacetDistribution
):Expected behavior
When calling the
multiSearch
function with the parameterqueries
of typeFederatedMultiSearchParams
I expect to have a response of typeSearchResponse
.Current behavior
The TS resolution shows that the return type is
MultiSearchResponse
.Screenshots or Logs
Environment (please complete the following information):
getmeili/meilisearch:v1.11
)"meilisearch": "^0.45.0",
)The text was updated successfully, but these errors were encountered: