在打字稿中导入lunr?

时间:2020-10-31 01:26:07

标签: javascript typescript typescript-typings lunrjs

Defintely Typed repository的导入方式如下:

import * as lunr from 'lunr';

但是,当在Stackblitz中使用它时,它会出现以下错误:

lunr不是函数

有什么想法吗?这是Stackblitz:

https://stackblitz.com/edit/typescript-lunr-test

2 个答案:

答案 0 :(得分:2)

“绝对类型”使用的是older version of lunr,因此我尝试了另一种导入:import lunr from "lunr",它抛出一个错误,指出posting[field]undefinedsource code

然后我注意到"text"中使用的Builder字段未在index中初始化。在this.field("text")中添加index导致页面加载没有错误。

答案 1 :(得分:1)

尝试使用:

import lunr from "lunr"

之所以如此有效,是因为lunr.js正在导出默认值或其使用单个内容覆盖导出对象。看一下本文的前4-5段:blog.atomist.com/typescript-imports