-
Notifications
You must be signed in to change notification settings - Fork 224
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
fix(types): union SearchForFacetValuesResponse type for multipleQueries #1460
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 70eaed3:
|
@Haroenv do you know why we did not made the union in the first place? |
I don't know the history of this, but I believe initially |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I feared this was a breaking change, as only MultipleQueriesResponse
is changed, this actually does not impact any code used by customers today (only the helper's internals, but that isn't typescript). I'm thus happy with the change after all. Sorry for the delay!
good to know! thanks for double checking |
@Haroenv fyi, it did impact us in a way: We depend on this typing a lot throughout our codebase |
Indeed, the type change has breaking impact, also on us. But it can be fixed easily by explicitly typing your |
Hello, We are indeed facing the same typing issue after the upgrade to Couldn't it be possible to improve the typing here by allowing the type to be sent as a generic so that way it could be defined directly when calling Or even better maybe the return type could be inferred based on the data sent in Thanks :) |
This also broke our search. How can we import the relevant types from the export const Algolia = {
async search<T = Record<string, string>[]>(
query: string,
params: Record<string, string | number> = {}
): Promise<{ hits: T; totalPages: number }> {
try {
const queries = BUILDER_MODELS.map((model) => {
return {
indexName: model,
query,
params: {
...params,
hitsPerPage: HITS_PER_PAGE,
},
}
})
const res = await client.multipleQueries(queries)
// Retrieve hits out of results and return
// @ts-expect-error
const hits = res?.results?.flatMap((result) => result.hits)
// @ts-expect-error
const pages = Math.max(...res.results.map((result) => result.nbPages))
return { hits: hits as T, totalPages: pages - 1 }
} catch (e) {
throw new Error(`Failed to load search data`)
}
},
} |
Summary
This PR unions
SearchForFacetValuesResponse
withSearchResponse<TObject>
as possible return types for results in themultipleQueries
API.Context
The
MultipleQueriesQuery
interface states that you can supply either adefault
or afacet
query. This is also confirmed by the Algolia documentation.However, the MultipleQueriesResponse definition does not include SearchForFacetValuesResponse as a possible return type. This is confusing because the response data from Algolia does in fact include facet responses when requested (see attached image).