修身养性,知行合一

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

TypeScript 类型找不到

2023年5月24日 2815点热度 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

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

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

文章评论

取消回复

最新 热点 随机
最新 热点 随机
Github Pages SPA 重定向 行间距引出的 DOCTYPE 怪异行为 写个小彩蛋 绘制一个可重用的线条阴影 node-sass 的安装 解决端口被占的问题
行间距引出的 DOCTYPE 怪异行为Github Pages SPA 重定向
关于 *.vue 文件中使用 TypeScript 声明类型报错的解决方案 SVG 宽高比与视口的关系 css实现跳动的文字 Terminal中git log不显示中文问题的解决方案 真丶深入理解 JavaScript 原型和原型链(三):继承 vue3 在 v-for 中实现双向绑定

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

COPYRIGHT © 2021 jeremyjone.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

京ICP备19012859号-1

京公网安备 11010802028585号