Defintely Typed repository的导入方式如下:
import * as lunr from 'lunr';
但是,当在Stackblitz中使用它时,它会出现以下错误:
lunr不是函数
有什么想法吗?这是Stackblitz:
答案 0 :(得分:2)
“绝对类型”使用的是older version of lunr,因此我尝试了另一种导入:import lunr from "lunr"
,它抛出一个错误,指出posting[field]
是undefined
(source code)
然后我注意到"text"
中使用的Builder
字段未在index
中初始化。在this.field("text")
中添加index
导致页面加载没有错误。
答案 1 :(得分:1)
尝试使用:
import lunr from "lunr"
之所以如此有效,是因为lunr.js正在导出默认值或其使用单个内容覆盖导出对象。看一下本文的前4-5段:blog.atomist.com/typescript-imports