-
-
Notifications
You must be signed in to change notification settings - Fork 757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix typescript issues with commonjs #124
Conversation
Thanks for creating a typescript definition! I have issues using it though... I expect to use it like this: ```ts import * as Fuse from 'fuse.js'; // - won't work since the actual "class" is inside fuse - Fuse.Fuse // or import {Fuse} from 'fuse.js'; // - won't work since there is no actual variable named Fuse inside Fuse // or import 'fuse.js'; - I can't see the global decleration if I import it that way since the UMD import doesn't declare global when commonjs is available const seachResults = new Fuse(rows ... ``` all of the above don't work, as a workaround I can do this: ```ts import * as F from 'fuse.js'; interface Type<T> extends Function { new (...args: any[]): T; } const Fuse: Type<F.Fuse> = <any>F; ``` but this is not ideal That's why I've changed the typescript definitions to something I can use out-of-the-box with commonjs.
Disclaimer: I am not an expert. Not at all. I've tested the pull request in webpack (Angular 2, Angular CLI which expects typescript@2.0.10, but same results with 2.1.4), and am getting some errors.
...tells me:
And
...gives me:
Next, for:
...I get:
Using a suggested
...or
...gets me:
Still investigating... |
I'm using |
tested the patch using |
@ronzeidman I am sorry for the confusion. I had a mistake in my answer on Stack Overflow. I neglected to nest the globally defined interface |
Anyone manage to get this working with Webpack? I've tried everything listed here and SO. Webpack still complains that it cannot find module |
Try using my fork: Import * as Fuse from 'fuse.js' Should work (that's what I'm doing, and I'm using webpack) |
I get the same error. Mind sharing your Webpack config? |
My declaration, from SO works. Here it is working, with Webpack 2. |
@aluanhaddad Thank you! I got it working using your fix when I converted to Webpack 2. |
Should work fine in Webpack 1 also. Just make sure you set the extension resolver. |
Is this still needed? |
Personally, I would say no because it will pollute the global namespace of ambient external module declarations preventing 2 versions of fuse.js from being used side by side without causing type errors. From what I can see, the library supports multi-versioning. |
Thanks for creating a typescript definition!
I have issues using it though...
I expect to use it like this:
all of the above don't work, as a workaround I can do this:
but this is not ideal
That's why I've changed the typescript definitions to something I can use out-of-the-box with commonjs.