Skip to content

Conversation

@xkr47
Copy link
Contributor

@xkr47 xkr47 commented Oct 17, 2025

Hi,

For at least the Search and Browse apis, there were a LOT of usage of Partial<...> when in fact almost all fields seem to always be present. I checked the api responses and also checked the online api documentation and these are the changes I feel pretty confident with. I hope you can consider at least most of these changes. I look forward to any feedback as well.

Instead of using Partial I tried to make only select fields optional using the ?: syntax. Also I split some interfaces into separate more specific ones to be able to provide better typings in all scenarios.

@xkr47 xkr47 requested review from esezen and jjl014 as code owners October 17, 2025 11:40
@xkr47 xkr47 force-pushed the fix/browse-and-search-types branch from 601719e to 09bcbaa Compare October 17, 2025 11:50
Comment on lines +81 to +84
export interface BrowseResponse<ResponseType, OmittedRequestFields extends keyof BrowseRequestType>
extends Record<string, any> {

request: Omit<BrowseRequestType, OmittedRequestFields>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I know the documentation says the format of the request object should not be programmatically relied on.. but otoh you have declared a type for the fields here, so I improved them at least a little bit..

>;
export type GetBrowseFacetOptionsResponse = BrowseResponse<
Pick<GetBrowseResultsResponseData, 'facets'>
Pick<GetBrowseResultsResponseData, 'facets' | 'total_num_results'>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The total_num_results is indeed included here as well

Comment on lines -98 to +102
Pick<GetBrowseResultsResponseData, 'facets' | 'total_num_results'>
GetBrowseFacetsResultsResponseData,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The facets response actually returns a lighter version of the facet data and therefore I made a separate interface for it.

}

export interface GetBrowseFacetsResultsResponseData extends Record<string, any> {
facets: BrowseFacet[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I defined the light-weight BrowseFacet in index.d.ts, thought it was more in-context there even though it is a browse-specific type..

filter_match_types?: Record<string, any>;
filters?: Record<string, any>;
fmt_options: FmtOptions;
facet_name: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

facet_name comes from /browse/facet_options endpoint

}

export interface HierarchialFacetOption extends FacetOption {
options?: HierarchialFacetOption[];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can the hierarchial facet option be recursive to to any depth? This typing assumes so. If it only allows two levels deep options, the type here should be replaced with FacetOption.

Also did not test this option so I don't know if it is always present or optional, so left it optional.

variations: Record<string, any>[];
variations_map: Record<string, any> | Record<string, any>[];
}
export type Result = BrowseResultData;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Result was identical so I thought we could just alias it here.

@esezen
Copy link
Contributor

esezen commented Oct 23, 2025

Hey @xkr47 , thanks for your contribution! We will review and get these merged

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.

2 participants