Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use fuse.js in Angular 2 application (typescript)

Tags:

I tried to import fuse.js in a angular2 app, but I get an exception (Fuse is not defined). I also check definitions file (index.d.ts) in the package.

my class in typescript is :

import 'fuse.js';

export class Myclass{

  /**some code*/

  public mySearchFunction(text, list, Opts){
    let fuseSearch  = new Fuse(list, Opts);
    let fuseResults: any[] = fuseSearch.search(text);
    return fuseResults
  }

}

I tried also with

import * as Fuse from 'fuse.js';

What is the right way to use this library?

like image 243
ilDug Avatar asked Nov 27 '16 21:11

ilDug


1 Answers

The typings were only added to the project 8 days ago. If you look at the latest NPM release from here you'll see the typings aren't included.

If you either pull the package from master or grab files package.json and index.d.ts, then you'll be able to use the package with import * as Fuse from 'fuse.js';

Looking at the console, I'm still getting error Cannot find module 'fuse.js', but it's working. Not sure what that's all about.

Version 2.6.1 got pushed to NPM yesterday, which supports typings - see here

like image 102
onetwothree Avatar answered Sep 22 '22 16:09

onetwothree