Better typescript type inference#497
Conversation
支持ts类型测试 - 添加types.ts 测试ts静态类型
- 导出了部分类型,这是为了支持类型测试 - 为`Document`添加泛型 - 在`Document`实例化时传入doc的类型,它将为所有返回doc的方法提供正确的类型 - 自动推断`search`,`searchCache`,`searchAsync`的返回类型,现在他们不再返回联合类型 - 为上述方法的`limit`参数单独使用函数重载,增加可读性 - 更新types.ts 测试ts静态类型
- 重构FieldName为泛型,支持自动推断字段定义 - 更新types.ts 测试ts静态类型
- 为Resolver添加泛型支持 - 更新types.ts 测试ts静态类型
This reverts commit 15a9ff3.
- 为Index的search等方法自动推断返回类型
|
|
@flycran thanks a lot, really great work 👍
|
|
@ts-thomas search的工作是否遵循这样的模式 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 |
|
@flycran Promises are right on every listed code example 👍 additionally: const indexPersistent = new Index();
// create db instance with optional prefix
const db = new IndexedDB("my-store");
// mount and await before transfering data
await indexPersistent.mount(db);
const db1 = indexPersistent.search({}); // Promiseconst indexPersistent2 = new Index({
db: new IndexedDB("my-store")
});
const db2 = indexPersistent2.search({}); // PromiseThe same for Document ... const documentIndexPersistent = new Document({});
// create db instance with optional prefix
const db = new IndexedDB("my-store");
// mount and await before transfering data
await documentIndexPersistent.mount(db);
const db1 = documentIndexPersistent.search({}); // Promiseconst documentIndexPersistent2 = new Document({
db: new IndexedDB("my-store"),
document: {}
});
const db2 = documentIndexPersistent2.search({}); // Promise |
|
@ts-thomas 你想表达调用 |
|
@flycran thanks for the hint. The most simple solution is to deprecate the using of |
- 修复`search`的返回值类型,根据worker、db推断返回类型 - 更新types.ts 测试ts静态类型
- 修复`search`的返回值类型,根据worker、db推断返回类型 - 更新types.ts 测试ts静态类型
|
@ts-thomas 你可以先将mount标记为deprecated |
|
@ts-thomas 我还有一些建议,可以考虑在下一个破坏性更新中应用
|
|
@flycran really great work, thanks a lot 💪. I need to investigate some time to understand some of the more complex definitions to keep it maintainable. Your suggestion to use |
|
Nice job @flycran, thanks! |
issue
#496 #396
Why
The meaning of this draft is to provide flexsearch with more comprehensive type inference and eliminate behavior that is inconsistent with expectations when used in typescript.
To disambiguate, the following will use Chinese
已完成
Document添加泛型,支持了文档内容的代码补全和静态类型检查Document的查询方法(search,searchAsync,searchCache),自动推断返回类型,不再返回联合类型,这一点非常重要且很有用Index的search等方法添加同上的支持DocumentSearchOptions.field/index/pluck和DocumentDescriptor.field/index/tag/store以及所有使用了FieldName的地方计划
Resolver添加泛型欢迎提出在类型方面的建议