From f8a73fe38bfcf0963bc518d6de414b4d48ffe22a Mon Sep 17 00:00:00 2001 From: Thomas Wilkerling Date: Fri, 9 May 2025 11:06:27 +0200 Subject: [PATCH] fix type delegation for "pluck" within index.d.ts --- index.d.ts | 6 +++--- test/types.ts | 40 +++++++++++++++------------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/index.d.ts b/index.d.ts index 40b341d..d02f78c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -502,7 +502,7 @@ declare module "flexsearch" { H extends HighlightOptions | boolean = false, R extends boolean = true, E extends boolean = false - > = FieldName | DocumentSearchOptions; + > = FieldName | DocumentSearchOptions; export type DocumentSearchResults< D extends DocumentData = DocumentData, @@ -955,12 +955,12 @@ declare module "flexsearch" { }; export type HighlightEllipsisOptions = { - template?: TemplateResultHighlighting; + template: TemplateResultHighlighting; pattern?: string | boolean; }; export type HighlightOptions = TemplateResultHighlighting | { - template?: TemplateResultHighlighting; + template: TemplateResultHighlighting; boundary?: HighlightBoundaryOptions | number; ellipsis?: HighlightEllipsisOptions | string | boolean; clip?: boolean; diff --git a/test/types.ts b/test/types.ts index 43a19a8..566148f 100644 --- a/test/types.ts +++ b/test/types.ts @@ -166,7 +166,7 @@ async function test_document() { const doc1: DefaultDocumentSearchResults = document.search({ cache: true }); const doc2: EnrichedDocumentSearchResults = document.search({ enrich: true }); const doc3: MergedDocumentSearchResults = document.search({ merge: true }); - const doc4: EnrichedDocumentSearchResults = document.search({ highlight: true }); + const doc4: EnrichedDocumentSearchResults = document.search({ highlight: { template: "" } }); const doc5: Promise = document.searchAsync({}); const doc6: DefaultSearchResults = document.search({ resolve: false }).resolve(); const doc7: DefaultDocumentSearchResults = document.search({ field: "title" }); @@ -186,51 +186,41 @@ async function test_document() { const doc21: DefaultSearchResults = doc20.resolve(); const doc22: EnrichedResults = doc20.resolve({ enrich: true }); // highlight within last resolver stage is work in progress: - const doc23: EnrichedResults = doc20.and({ resolve: true, highlight: true }); + const doc23: EnrichedResults = doc20.and({ resolve: true, highlight: { template: "", boundary: {} } }); const doc24: Resolver = new Resolver({ index: document }); const doc25: EnrichedResults = doc24.and({}, { index: document2, resolve: true, enrich: true }); const doc26: EnrichedResults = doc24.and({}, { index: document2 }).resolve({ enrich: true }); // highlight within last resolver stage is work in progress: - const doc27: EnrichedResults = doc24.and({}, { index: document2, resolve: true, highlight: true }); + const doc27: EnrichedResults = doc24.and({}, { index: document2, resolve: true, highlight: "" }); // highlight on .resolve() is never supported: // @ts-expect-error - const doc28: EnrichedResults = doc24.resolve({ highlight: true }); + const doc28: EnrichedResults = doc24.resolve({ highlight: "" }); // @ts-expect-error - let tmp1: DocumentData = doc1[0].result[0].doc; - let tmp2: DocumentData = doc2[0].result[0].doc; - let tmp3: DocumentData = doc3[0].doc; + const err1: DocumentData = doc1[0].result[0].doc; + const err2: DocumentData = doc2[0].result[0].doc; + const err3: DocumentData = doc3[0].doc; // @ts-expect-error - const t_2_1: DefaultSearchResults = document2.search({ pluck: "title" }); + const err4: DefaultSearchResults = document2.search({ pluck: "title" }); // @ts-expect-error - const t_2_2: DefaultSearchResults = document.search("test", {}); + const err5: DefaultSearchResults = document.search("test", {}); // @ts-expect-error - const t_4_3: Resolver = document.search({}); + const err6: Resolver = document.search({}); // @ts-expect-error - const t_4_4: Resolver = document.search({ resolve: true }); + const err7: Resolver = document.search({ resolve: true }); // @ts-expect-error - const docw6: DefaultDocumentSearchResults = await document.searchAsync({}); + const err8: DefaultDocumentSearchResults = document.searchAsync({}); // @ts-expect-error - const docw7: DefaultDocumentSearchResults = await document.searchAsync({ pluck: false }); + const err9: DefaultDocumentSearchResults = await document.searchAsync({ pluck: "title" }); // @ts-expect-error - const docw8: DefaultDocumentSearchResults = await document.searchAsync({ enrich: false }); - + const err10: DefaultDocumentSearchResults = await document.searchAsync({ enrich: true }); // @ts-expect-error - const docw4: Resolver = await document.searchAsync({}); - // @ts-expect-error - const docw5: Resolver = await document.searchAsync({ resolve: true }); - // @ts-expect-error - const docw6: DefaultDocumentSearchResults = await document.searchAsync({}); - // @ts-expect-error - const docw7: DefaultDocumentSearchResults = await document.searchAsync({ pluck: false }); - // @ts-expect-error - const docw8: DefaultDocumentSearchResults = await document.searchAsync({ enrich: false }); - + const err11: EnrichedDocumentSearchResults = document.search({ highlight: {} }); } async function test_worker() {