1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-08-28 08:10:54 +02:00

- 更新index.d.ts

- 为Index的search等方法自动推断返回类型
This commit is contained in:
flycran
2025-05-05 11:05:50 +08:00
parent babbe1d73c
commit a685bc1f8f

43
index.d.ts vendored
View File

@@ -108,8 +108,8 @@ declare module "flexsearch" {
? { ? {
[K in keyof D]: K extends string [K in keyof D]: K extends string
? D[K] extends Array<infer U> ? D[K] extends Array<infer U>
? `${K}` | `${K}[]:${FieldName<U> & string}` ? `${ K }` | `${ K }[]:${ FieldName<U> & string }`
: K | `${K}:${FieldName<D[K]> & string}` : K | `${ K }:${ FieldName<D[K]> & string }`
: never : never
}[keyof D] }[keyof D]
: never : never
@@ -219,7 +219,7 @@ declare module "flexsearch" {
type DefaultSearchResults = Id[]; type DefaultSearchResults = Id[];
type IntermediateSearchResults = Array<Id[]>; type IntermediateSearchResults = Array<Id[]>;
type SearchResults = DefaultSearchResults | Resolver; type SearchResults<R extends boolean = false> = R extends true ? Resolver : DefaultSearchResults;
/** /**
* **Document:** * **Document:**
@@ -242,13 +242,15 @@ declare module "flexsearch" {
remove(id: Id): this | Promise<this>; remove(id: Id): this | Promise<this>;
search(query: string, options?: Limit | SearchOptions): SearchResults | Promise<SearchResults>; search(query: string, limit?: Limit): SearchResults | Promise<SearchResults>;
search(query: string, limit: number, options: SearchOptions): SearchResults | Promise<SearchResults>; search<R extends boolean = false>(query: string, options?: SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
search(options: SearchOptions): SearchResults | Promise<SearchResults>; search<R extends boolean = false>(query: string, limit: Limit, options: SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
search<R extends boolean = false>(options: SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
searchCache(query: string, options?: Limit | SearchOptions): SearchResults | Promise<SearchResults>; searchCache(query: string, limit?: Limit): SearchResults | Promise<SearchResults>;
searchCache(query: string, limit: number, options: SearchOptions): SearchResults | Promise<SearchResults>; searchCache<R extends boolean = false>(query: string, options?: Limit | SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
searchCache(options: SearchOptions): SearchResults | Promise<SearchResults>; searchCache<R extends boolean = false>(query: string, limit: Limit, options: SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
searchCache<R extends boolean = false>(options: SearchOptions<R>): SearchResults<R> | Promise<SearchResults<R>>;
// https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids // https://github.com/nextapps-de/flexsearch#check-existence-of-already-indexed-ids
contain(id: Id): boolean | Promise<boolean>; contain(id: Id): boolean | Promise<boolean>;
@@ -299,19 +301,24 @@ declare module "flexsearch" {
searchAsync( searchAsync(
query: string, query: string,
options?: Limit | SearchOptions, limit?: Limit,
callback?: AsyncCallback<SearchResults>, callback?: AsyncCallback<SearchResults>,
): Promise<SearchResults> ): Promise<SearchResults>
searchAsync( searchAsync<R extends boolean = false>(
query: string,
options?: SearchOptions<R>,
callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults<R>>
searchAsync<R extends boolean = false>(
query: string, query: string,
limit: Limit, limit: Limit,
options?: SearchOptions, options?: SearchOptions<R>,
callback?: AsyncCallback<SearchResults>, callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults>; ): Promise<SearchResults<R>>;
searchAsync( searchAsync<R extends boolean = false>(
options: SearchOptions, options: SearchOptions<R>,
callback?: AsyncCallback<SearchResults>, callback?: AsyncCallback<SearchResults<R>>,
): Promise<SearchResults>; ): Promise<SearchResults<R>>;
} }
/** /**