I have been trying to implement the pre-fetch feature from Typeahead's website using Typescript.
After including the typeahead.d.ts file, everything seems to be fine until I attempt to use a Bloodhound instance as the dataset source.
The original example code looks like this:
var countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: '../data/countries.json'
});
$('#prefetch .typeahead').typeahead(null, {
name: 'countries',
source: countries
});
In my Typescript conversion, it appears as follows:
// Configuration for employee search box
var emps = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: { url: prefetchUrl }
});
$("#employee").typeahead(null, {
name: "emps",
source: emps
});
However, I encounter an error message which states:
Argument of type '{ name: string; source: Bloodhound<{}>; }' is not assignable to parameter of type 'Dataset'.
Types of property 'source' are incompatible.
Type 'Bloodhound<{}>' is not assignable to type '(query: string, cb: (result: any) => void) => void'.
If anyone can guide me on correcting my translation or modifying the d.ts file for successful compilation, I would greatly appreciate it.
Although the JavaScript functionality works perfectly fine, these Typescript errors are hindering the build process of my project.
Thank you!