修身养性,知行合一

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

TypeScript 类型找不到

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

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

打赏 点赞
< 上一篇

文章评论

取消回复

最新 热点 随机
最新 热点 随机
TypeScript 类型找不到 iOS 正则匹配问题 我的开源组件 @xpyjs/gantt 100颗星星啦 volar 检查 element 表格的 slot-scope 错误 关于 *.vue 文件中使用 TypeScript 声明类型报错的解决方案 element table 加载时宽度闪烁问题
TypeScript 类型找不到
我的开源组件 @xpyjs/gantt 100颗星星啦 vue3上手 -- 更新 jz-gantt 小记 JavaScript 之 canvas(一) vue2 使用 @vue/composition-api 的一些问题 Windows自动连接跨域共享盘 WSL 安装问题 0x8007019e、0x800701bc、0x80370102

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

COPYRIGHT © 2021 jeremyjone.com. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

京ICP备19012859号-1

京公网安备 11010802028585号