I just downloaded the typeahead.js d.ts file, but how the hell do you use it ?
The options object has to be written in this format:
let a:Twitter.Typeahead.Options = {};
But how do I define the source ?
This is causing a compiler error-:
let b:Twitter.Typeahead.Dataset<string> =
{source:{query:'',syncResults:null,asyncResults:null}};
Can someone help me with the syntax ?
EDIT: Solved it:
here is the code I used in typescript-: You need jquery, for $.each() function.
private sourceFactory(list: string[]):
(query: string, syncResults: (results: string[]) => void) => void {
return (query: string, syncResults: (results: string[]) => void) => {
let matches: string[] = [];
let regex: RegExp = new RegExp('^' + query, 'i');
$.each(list, (i: number, str: string) => {
if (regex.test(str)) {
matches.push(str);
}
});
syncResults(matches);
}
}