Skip to content

fix(types): use collection field in UnionSearchResponseRequestParams#350

Open
rachit367 wants to merge 1 commit into
typesense:masterfrom
rachit367:fix-union-search-collection-field
Open

fix(types): use collection field in UnionSearchResponseRequestParams#350
rachit367 wants to merge 1 commit into
typesense:masterfrom
rachit367:fix-union-search-collection-field

Conversation

@rachit367

Copy link
Copy Markdown

Fixes #321.

UnionSearchResponseRequestParams extends SearchResponseRequestParams, which declares collection_name?: string. But for a union multi-search, the server returns the per-search entry under union_request_params with the field named collection (matching the field name used in the request), not collection_name. The current type forces callers to widen or cast every time they read union_request_params[i].collection.

Override the field on the union variant: omit collection_name from the inherited shape and add collection: string. Regular SearchResponseRequestParams (used by SearchResponse.request_params) is unchanged.

Confirmed against the response shape from the issue:

{
  "union_request_params": [
    { "collection": "collection_one", "first_q": "test", "found": 30, ... }
  ]
}

No runtime code touched; this is types-only.

@tharropoulos

Copy link
Copy Markdown
Collaborator

Which version of Typesense was this tested on? A PR to return collection_name (to match the rest of the search request responses) was added to Typesense on August 2025: typesense/typesense#2473.

This has been the case for all major Typesense versions after 29.0.

@tharropoulos tharropoulos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave a TODO comment underneath the collection prop, we should deprecate this.

Comment thread src/Typesense/Types.ts

export interface UnionSearchResponseRequestParams
extends AllRequiredBut<SearchResponseRequestParams, "voice_query"> {
extends Omit<

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove the omit, keep it as an optional prop and add collection as optional as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SearchResponseRequestParams doesn't match with actual API response

2 participants