最近写了一个库发布到了 npm 源码使用的 TypeScript 开发的,然后用了 vite 进行打包,现在我已经发布到 npm 上面了 但是在使用的时候引入包的时候会出现 ts 的错误,因为打包之后没有 dts 文件 不知道要怎么给打包到 npm 的包添加需要暴露的 dts 文件 这个是 npm 的包地址: https://www.npmjs.com/package/liteofd 下面是我在 demo 项目里面引入的报错
import { LiteOfd, OfdDocument } from 'liteofd'
Could not find a declaration file for module 'liteofd'. 'node_modules/liteofd/dist/liteofd.es.js' implicitly has an 'any' type.
There are types at 'node_modules/liteofd/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'liteofd' library may need to update its package.json or typings.
下面的图是打包发布到 npm 上面的结构
我在网上也查询了,但是因为不是前端开发,所以一直没弄好如何给这个项目添加 dts
希望熟悉 TypeScript 的各位帮帮忙帮我看看我要怎么改项目添加 dts 文件让用户引用包不会报错
ps:dts-gen 我也安装并按照网上的使用还是不行,就报错说 module 的问题