Jeremy Danyow Jeremy Danyow - 1 month ago 19
TypeScript Question

TypeScript: @types package name does not match implementation package name

What do you do when the npm package containing the typings does not match the name of the package containing the implementation?

For example,

contains the type definitions for FileSaver.js, whose npm package name is
file-saver
.

Background info: the future of declaration files

tsconfig.json:

{
"compilerOptions": {
"module": "commonjs",
"moduleResolution": "node",
...

Answer

In the future, you can git mv the folder in DefinitelyTyped and send us a pull request to the types-2.0 branch (or whichever branch hosts the state of @types). I've done this for you with this pull request.

In the mean time, you can add the "types" field to your tsconfig.json's "compilerOptions" field, and set it to ["filesaver"]. This will tell TypeScript to load in the declaration for you so that you can correctly import file-saver.

Here's an example of how it should look:

{
    "compilerOptions": {
        // ...
        "types": ["filesaver"]
    }
}