TypeScript introduces the js third-party package, and cannot find the declaration file xxx of the module "xxx.js" implicitly has the "any" type

The language used in the project is TypeScript . When I introduced js into the project, I found an error:
the prompt message was: the declaration file xxx of the module "xxx.js" could not be found, which implicitly has the "any" type

 The introduction of js in typeScript cannot be introduced directly in this way. The following are two solutions I know:

1. The first method: use requirethe traditional import instead of import:

const waterMark = require("@/utils/waterMark");

2. The second method: create a new xxx.d.ts file in the project: actively declare the imported module in the file:

insert image description here

declare module '@/utils/waterMark.js'
declare module '@/config/api.js'

 

Guess you like

Origin blog.csdn.net/weixin_46600931/article/details/129425620