修身养性,知行合一

  • 首页
  • 爱码
    • 系统
    • 数据库
    • JavaScript
    • CSharp
    • Python
  • 生活
    • 文化
    • 美食
  • 杂谈
  • 关于
修身养性,知行合一
码字,杂谈
  1. 首页
  2. 爱码
  3. 前端
  4. 正文

TypeScript 类型找不到

2023年5月24日 2621点热度 0人点赞 0条评论

今天倒库的时候,提示:

Could not find a declaration file for module 'xxx' implicitly has an 'any' type.
  There are types at 'xxx/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'xxx' library may need to update its package.json or typings.ts(7016)

在新版 TypeScript 中,已经不在使用 package.json 根结构中的 types 字段。而是需要在 exprots 中添加 typs 字段,如:

// package.json
{
    "name": "my-package",
    "type": "module",
    "exports": {
        ".": {
            "import": {
                // 这里添加声明文件
                "types": "./types/esm/index.d.ts",
                "default": "./esm/index.js"
            },
            "require": {
                // 这里添加声明文件
                "types": "./types/commonjs/index.d.cts",
                "default": "./commonjs/index.cjs"
            },
        }
    },
    // 旧版本声明
    "types": "./types/index.d.ts"
}

具体内容:https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing

好像是从 v4.7 开始的。

本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可
标签: TypeScript
最后更新:2023年5月24日

jeremyjone

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

最新 热点 随机
最新 热点 随机
node-sass 的安装 解决端口被占的问题 vue3 组件 Props 的声明方式 给 div 添加选中状态 请求的取消 rgb 颜色小数兼容问题
rm -rf 仍然提示的处理方法 充分利用公网 -- 将联通光猫设置为桥接 使用 nvm 安装时的小问题 rolling back Qt lnk1158 无法运行rc.exe 的解决方案 Windows Server 2019安装与配置(三) 将 .net core 项目部署到 Linux(含配置多个项目)

(っ•̀ω•́)っ✎⁾⁾ 开心每一天

COPYRIGHT © 2021 jeremyjone.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

京ICP备19012859号-1

京公网安备 11010802028585号