-
Notifications
You must be signed in to change notification settings - Fork 224
Closed
Description
HighlightResult/SnippetResult are defined as:
export type HighlightResult<THit> = THit extends string | number
? HighlightMatch
: {
[KAttribute in keyof THit]?: HighlightResult<THit[KAttribute]>;
};
export type SnippetResult<THit> = THit extends string | number
? SnippetMatch
: {
[KAttribute in keyof THit]: SnippetResult<THit[KAttribute]>;
};which resolves to HighlightMatch/SnippetMatch if THit is a string | number, else recurses.
This unfortunately means that array properties/attributes of THit will not resolve to HighlightMatch/SnippetMatch.
See related issue meilisearch/meilisearch-js-plugins#552 (comment)
Since the recursion is meant to support nested Objects, maybe the type definitions can be changed to:
export declare type HighlightResult<THit> = THit extends object
? THit extends Array<any>
? HighlightMatch
: {
[KAttribute in keyof THit]: HighlightResult<THit[KAttribute]>;
}
: HighlightMatch;
export declare type SnippetResult<THit> = THit extends object ?
? THit extends Array<any>
? SnippetMatch
: {
[KAttribute in keyof THit]: SnippetResult<THit[KAttribute]>;
}
: SnippetMatch;which would support all primitives and arrays.
I wish TypeScript had an easier way to define (object | !Array). Sadly Exclude<object, Array<any>> doesn't work with object.
Metadata
Metadata
Assignees
Labels
No labels