修身养性,知行合一

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

TypeScript 类型找不到

2023年5月24日 2750点热度 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 添加选中状态
.NET Core将Json字符串反序列化为对象 vue3 在 v-for 中实现双向绑定 Vue移动项目切换页面时不同动画的实现小技巧 你好,世界! JavaScript 之 canvas(三)-- 使用鼠标实时绘制图形 若您正以管理员身份运行 Visual Studio Code - Insiders 用户范围的安装,更新功能会被禁用。

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

COPYRIGHT © 2021 jeremyjone.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

京ICP备19012859号-1

京公网安备 11010802028585号