今天倒库的时候,提示:
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"
}
好像是从 v4.7 开始的。
文章评论