Typescript implicitly has an 'any' type


Sometimes you find a module that typescript will not let you import. If you cannot find it in npm and in definitelytyped.org, here’s a simple fix:

Fix

Declare a file with some naming convention. As multiple of these can be imported, naming them semantically makes sense.

external_modules.d.ts

declare module "<module name>"

tsconfig.json

{
    ...
    "include": [
        ...
        "external_modules.d.ts"
    ]
}

Thoughts

  • Coupled with multiple different files that relate to categories such as ‘external’, ‘internal’, and ‘todo’ makes sense to me.
  • This is just a hack, as you are essentially lying to the ts compiler that these modules are typed… not a good solution long term, especially for maintaining, good for quick hacks and MVP.

Sources