【问题标题】:Could not find a declaration file for module 'mymodule'找不到模块“mymodule”的声明文件
【发布时间】:2022-01-21 19:04:34
【问题描述】:

我尝试导入使用 npm i github.com/.../... 和代码安装的测试模块,它工作正常,但在 VSCode 中它有这样的内容:

Could not find a declaration file for module 'estrajs'. 'C:/Users/Users/Desktop/Test/TestFolder/node_modules/mymodule/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/mymodule` if it exists or add a new declaration (.d.ts) file containing `declare module 'mymodule';`ts(7016)

如何声明它?我已经在 typings/index.d.ts 上制作了文件

【问题讨论】:

  • 确保在 tsconfig 中包含您的类型定义根目录,还尝试在 VS Code 中重新启动 TS 服务器,您可以看到我在 github.com/Maxim-Mazurok/google-api-typings-generator 中使用 typings 文件夹进行的操作,但是否则没有足够的细节来回答

标签: javascript node.js angular typescript


【解决方案1】:

啊,我想通了,我只是在 index.d.ts 文件中输入

declare module 'mymodule';

【讨论】:

    【解决方案2】:

    尝试将以下内容添加到 tsconfig.json 文件中

    "noImplicitAny": false
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2017-08-13
    • 1970-01-01
    • 2021-01-02
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-26
    相关资源
    最近更新 更多