Skip to content
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

javascript: certain types aren't generic #853

Open
Haroenv opened this issue Jul 20, 2022 · 6 comments
Open

javascript: certain types aren't generic #853

Haroenv opened this issue Jul 20, 2022 · 6 comments
Labels
Java Issue related to the Java client JavaScript Issue related to the JavaScript client

Comments

@Haroenv
Copy link
Contributor

Haroenv commented Jul 20, 2022

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;
};
@shortcuts
Copy link
Member

Thanks! This is being worked on for Java and JavaScript here: #829

@millotp
Copy link
Collaborator

millotp commented Jul 20, 2022

Should the hit be overridden by the generic ? like hits: T[] and it's up to the user to extend its type with Hit ?

@shortcuts
Copy link
Member

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 }

@millotp
Copy link
Collaborator

millotp commented Jul 20, 2022

Okay so the generic logic will be exclusively for hits, it would be hard to make it work with other generic type

@shortcuts shortcuts added JavaScript Issue related to the JavaScript client Java Issue related to the Java client labels Jul 20, 2022
@Haroenv
Copy link
Contributor Author

Haroenv commented Sep 7, 2022

Is there a plan for Highlight and Snippet to be correct as well?

@shortcuts
Copy link
Member

Not for now as we have other priorities, but if you have an implementation in mind feel free to contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Java Issue related to the Java client JavaScript Issue related to the JavaScript client
Projects
None yet
Development

No branches or pull requests

3 participants