我遵循pre-fetch example from the Typeahead site,但我正在使用Typescript。Twitter Typeahead - 打字稿中的Bloodhound错误
我拉了typeahead.d.ts file,没关系,直到我尝试使用Bloodhound实例作为数据集源。
的例子是这样的:
var countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// url points to a json file that contains an array of country names, see
// https://github.com/twitter/typeahead.js/blob/gh-pages/data/countries.json
prefetch: '../data/countries.json'
});
// passing in `null` for the `options` arguments will result in the default
// options being used
$('#prefetch .typeahead').typeahead(null, {
name: 'countries',
source: countries
});
所以我翻译成打字稿看起来是这样的:
// typeahead for the employees box
var emps = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: { url: prefetchUrl }
});
$("#employee").typeahead(null, {
name: "emps",
source: emps
});
要么我已经翻译了JS错误或d.ts文件是错误的,因为发生以下错误:
类型'{name:string;来源:Bloodhound < {}>; }'不能分配给'Dataset'类型的参数。
属性“来源”的类型不兼容。 (查询:字符串,cb:(结果:任何)=>无效)=>无效'。'}不可分配给类型'(查询:字符串,cb:(结果:任何)=>无效)=>无效'。
任何人都可以告诉我我做错了什么或我需要在d.ts文件中修改以获得此编译?
由此创建的JavaScript实际上正常工作,但Typescript错误阻止了我的项目建立。
干杯。
我很想更新d.ts文件,但我以前从未编写过一个。我尝试了一些调整,但只是打破了:(时间做一些阅读也许。 – Nick
@尼克我只是更新答案,以尝试在你的本地d。如果这样的作品,你可以创建/提交一个拉请求,肯定键入 – Brocco
关闭,但编辑抛出错误“通用类型'Bloodhound'需要1个类型参数。 –
Nick