修身养性,知行合一

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

TypeScript 类型找不到

2023年5月24日 2657点热度 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 添加选中状态 请求的取消
绘制一个可重用的线条阴影
JS 中字符串 replace 的高级用法 Apache部署多网站(二级域名同理) 小技巧系列 - JS判断图片是否已经缓存 Windows Server 无法安装网卡驱动的解决方案 MySQL升级之路(5.6-8.0) 实现ElementPlus炫酷的亮暗切换效果

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

COPYRIGHT © 2021 jeremyjone.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

京ICP备19012859号-1

京公网安备 11010802028585号