Fix typings based on TypeScript guidelines #129
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the GitHubified text of my Stack Overflow answer, verbatim
OK, here is what is happening and why.
Firstly, Fuze/index.d.ts attempts to declare itself as both a global and as an ambient external module but does both of these incorrectly. This makes misuse, such as that which led your error almost inevitable.
It contains a module declaration that contains a class declaration, presumably with the intent of describing the shape of the module but the class is not exported.
This means that I cannot import the module correctly and in fact there is a type error when trying to import a value and/or type from it.
Further down in Fuse/index.d.ts it declares its global
declare const Fuse;
Presumably, based on conventions and reading the comments in the actual JavaScript, this is meant to have the same shape as what is exported from the module. Unfortunately, it has type any which is neither the same type as the attempted module, because it isn't valid, nor the the type of the class Fuse which is trapped inside said module but not exported...
So why the error? You probably have one of the following somewhere in your program: import 'fuse'; import Fuse from 'fuse'; import * as Fuse from 'fuse';
followed by some use of Fuse like
const myFuse = new Fuse();
This will cause an import for the runtime representation of Fuse fuse to be emitted by TypeScript, so that you can use the value imported from the module.
To fix the problem, you can use the global const Fuse and not import it anywhere. Unfortunately that is not what is intended. The author almost certainly meant to have the following content in Fuze/index.d.ts:
Which declares a class which is either available globally, for those not using ES Modules, or via an import for those who are. You can use the above UMD style declaration to gain the typing experience the author intended. The one bundled with the library provides no type information and actually results in errors when used.
Consider sending a pull request to the maintainer with the fix.
Usage:
You can use this declaration in the following ways:
CommonJS TypeScript style
Legacy CommonJS style
ES with CommonJS interop style
(when using "module": "system" or "allowSyntheticDefaltImportsTrue") with SystemJS or if piping through Babel.