1
0
mirror of https://github.com/nextapps-de/flexsearch.git synced 2025-09-01 09:53:56 +02:00

- 更新index.d.ts

- 修复`search`的返回值类型,根据worker、db推断返回类型

- 更新types.ts
  测试ts静态类型
This commit is contained in:
flycran
2025-05-06 17:23:36 +08:00
parent a685bc1f8f
commit f32268c902
2 changed files with 91 additions and 41 deletions

View File

@@ -1,20 +1,26 @@
import { DefaultDocumentSearchResults, Document, Resolver } from "flexsearch";
import {
DefaultDocumentSearchResults,
Document,
Index,
Worker,
Resolver,
StorageInterface,
} from "flexsearch";
import "../index";
const document = new Document<{
title: string
description: string
tags: {
name: string
id: number
}[]
}>({
document: {
index: ["tags"],
},
});
async function test() {
const document = new Document<{
title: string
description: string
tags: {
name: string
id: number
}[]
}>({
document: {
index: [ "tags" ],
},
});
// The correct type
const doc1 = await document.searchAsync({});
const doc2: Resolver = await document.searchAsync({
@@ -35,6 +41,30 @@ async function test() {
const docw2: DefaultDocumentSearchResults = await document.searchAsync({
enrich: true,
});
// ...
// Promise?
const documentNoWorker = new Document({});
const doc5 = documentNoWorker.search({}); // No Promise
const documentWorker = new Document({
worker: true,
});
const doc6 = await documentWorker.search({}) // Promise
const documentWorker2 = new Document({
worker: '...',
});
const doc7 = await documentWorker2.search({}) // Promise
const index = new Index({})
const idx = index.search({}) // No Promise
const worker = new Worker()
const wkr = await worker.search({}) // Promise
const documentDb = new Document({
db: {} as unknown as StorageInterface
})
const doc8 = documentDb.search({}) // Promise
}