api-clients-automation
api-clients-automation copied to clipboard
javascript: certain types aren't generic
Description
- SearchResponse, SearchResponses should take a single generic THit
- HighlightResult and SnippetResults should take a single generic THit
SnippetResults and HighlightResult should also be recursive as in v4
declare type SnippetMatch = {
readonly value: string;
readonly matchLevel: 'none' | 'partial' | 'full';
};
export declare type SnippetResult<THit> = THit extends string | number ? SnippetMatch : {
[KAttribute in keyof THit]: SnippetResult<THit[KAttribute]>;
};
declare type HighlightMatch = {
readonly value: string;
readonly matchLevel: 'none' | 'partial' | 'full';
readonly matchedWords: readonly string[];
readonly fullyHighlighted?: boolean;
};
export declare type HighlightResult<THit> = THit extends string | number ? HighlightMatch : {
[KAttribute in keyof THit]?: HighlightResult<THit[KAttribute]>;
};
export declare type Hit<THit> = THit & {
readonly objectID: string;
readonly _highlightResult?: HighlightResult<THit>;
readonly _snippetResult?: SnippetResult<THit>;
readonly _rankingInfo?: RankingInfo;
readonly _distinctSeqID?: number;
};
Thanks! This is being worked on for Java and JavaScript here: https://github.com/algolia/api-clients-automation/pull/829
Should the hit be overridden by the generic ? like hits: T[]
and it's up to the user to extend its type with Hit
?
Should the hit be overridden by the generic ?
It should be type Hits<T> = Array<Hit<T>>
and type Hit<T = Record<string, any>> = T & { ...baseProps }
Okay so the generic logic will be exclusively for hits, it would be hard to make it work with other generic type
Is there a plan for Highlight and Snippet to be correct as well?
Not for now as we have other priorities, but if you have an implementation in mind feel free to contribute!