Error when importing untyped JS modules

Sami C.
1 min readSep 14, 2019

--

tldr;

Create a global.d.ts and add:

declare module '*';

My Situation

When reworking a legacy application, I found out that a lot of these libraries did not have any typings, nor were they build in a modular way.

In our modern day javascript we are used to

import { export1 } from "module-name";

This was not possible before ES6. So let’s say we are going to import a bootstrap-treeview library (pretty old), we could do it like this:

import 'bootstrap-treeview';

When having ‘ noImplicitAny: true’ in your tsconfig, typescript will complain that the import is of type any. To fix this issue simply add a global.d.ts and add the following:

declare module '*';

It automatically makes all js modules any while ts modules keep working as intended.

Now you are free to import any js modules without typings!

A quick tip I can give you is to add typings in the long run, these will save you and your fellow developers a lot of time and headaches.

More information on the issue can be found here:

Thanks for reading and happy coding!

--

--

Sami C.
Sami C.

Written by Sami C.

Freelance Software Engineer

No responses yet