Although this question has been asked and answered multiple times since 2017, I have been struggling to make it work for my project. Specifically, I have set noImplicitAny: true
in my tsconfig.json
, and I am trying to utilize the clamscan
package which does not have native typing nor is available in @types
. This issue is not limited to just this package.
When I try to import NodeClam from 'clamscan'
in my code.ts
file, I encounter the following error:
Could not find a declaration file for module 'clamscan'. '.../node_modules/clamscan/index.js' implicitly has an 'any' type.
Try `npm install @types/clamscan` if it exists or add a new declaration (.d.ts) file containing `declare module 'clamscan';`ts(7016)
To address this issue, I created a clamscan.d.ts
file with the following content:
declare module 'clamscan' {
// the declarations I use
}
I also attempted just using declare module 'clamscan';
, but in both cases, I received the error:
Invalid module name in augmentation. Module 'clamscan' resolves to an untyped module at '.../node_modules/clamscan/index.js', which cannot be augmented.ts(2665)
While declare module '*';
was accepted by the compiler, it did not fully resolve my original error. Therefore, my question remains: How can I effectively type an untyped external npm module?
Although I am aware that contributing to DefinitelyTyped or the clamscan package could provide a solution, I am specifically interested in annotating or augmenting the package locally for my own project.