Typescript: ignore imlicitly any type when importing js module

In the Typescript project, I need to import some old js files that make module.exports inside myself.

How do I import:

import * as httpConnection from '...path...';

I got errors from the compiler:

Could not find a declaration file for module '...path...'. '...path...' implicitly has an 'any' type.

After that, it works fine, but I need to avoid this error in the console.

How can I make the compiler understand that import is of any type without creating a declaration file?

Thanks for the ideas in advance.

+4
source share
1 answer

This means that you must enter this module. Typescript is unhappy that this module implicitly does not have any definition file.

If it is an external open module, you can simply set its types with npm install @types/name_of_the_module

, .d.ts, . , , any .d.ts

declare var name_of_the_module: any;

declare module "name_of_the_module" {
    export = name_of_the_module;
}
+1

Source: https://habr.com/ru/post/1665094/


All Articles