首页 前端技术 正文
  • 本文约547字,阅读需3分钟
  • 101
  • 2

安装依赖插件但是没有官方的类型声明包

报错: Could not find a declaration file for module 'crypto-js'. 'G:/company-projects/sw-fe-auth/node_modules/crypto-js/index.js' implicitly has an 'any' type.

Could not find a declaration file for module 'crypto-js'. 'G:/company-projects/sw-fe-auth/node_modules/crypto-js/index.js' implicitly has an 'any' type.

方法一:官方的类型声明包

npm i --save-dev @types/crypto-js(如果报错,执行方法 二)

方法二:创建自定义声明文件

在项目根目录下创建一个 custom-typings.d.ts 文件,并添加以下内容:

// custom-typings.d.ts
declare module 'crypto-js';

然后确保项目中的 tsconfig.json 中包含这个声明文件:

{
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types", "./custom-typings.d.ts"]
  }
}
收藏



扫描二维码,在手机上阅读
    评论
    $comment['poster']
    119.123.78.246 ChromeWindows 10
    [太开心]
    28 天前
    $comment['poster']
    113.116.245.195 ChromeWindows 10
    [狗头]
    29 天前
    友情链接