mirror of
https://github.com/nextapps-de/flexsearch.git
synced 2025-09-02 18:33:17 +02:00
- 更新index.d.ts
- 导出了部分类型,这是为了支持类型测试 - 为`Document`添加泛型 - 在`Document`实例化时传入doc的类型,它将为所有返回doc的方法提供正确的类型 - 自动推断`search`,`searchCache`,`searchAsync`的返回类型,现在他们不再返回联合类型 - 为上述方法的`limit`参数单独使用函数重载,增加可读性 - 更新types.ts 测试ts静态类型
This commit is contained in:
@@ -1,16 +1,33 @@
|
||||
import { Document } from 'flexsearch'
|
||||
import '../index'
|
||||
import { DefaultDocumentSearchResults, Document, Resolver } from "flexsearch";
|
||||
import "../index";
|
||||
|
||||
const document = new Document<{
|
||||
title: string
|
||||
description: string
|
||||
tags: string[]
|
||||
}>({})
|
||||
title: string
|
||||
description: string
|
||||
tags: string[]
|
||||
}>({});
|
||||
|
||||
async function test() {
|
||||
const doc = await document.searchAsync('test', {
|
||||
enrich: true,
|
||||
pluck: 'test',
|
||||
})
|
||||
// The correct type
|
||||
const doc1 = await document.searchAsync({});
|
||||
const doc2: Resolver = await document.searchAsync({
|
||||
resolve: true,
|
||||
});
|
||||
const doc3 = await document.searchAsync({
|
||||
enrich: true,
|
||||
});
|
||||
const doc4 = await document.searchAsync({
|
||||
enrich: true,
|
||||
merge: true,
|
||||
});
|
||||
doc4[0].doc.title;
|
||||
// The wrong type
|
||||
// @ts-expect-error
|
||||
const docw1: Resolver = await document.searchAsync({});
|
||||
// @ts-expect-error
|
||||
const docw2: DefaultDocumentSearchResults = await document.searchAsync({
|
||||
enrich: true,
|
||||
});
|
||||
// ...
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user