自己开发的lib库,rollup打包时也生成了.d.ts代码
interface BearType {
id: number;
createAt: string;
}
declare class Bear {
list: BearType[];
constructor();
save: () => void;
add: (p: BearType) => void;
getOneById: (queueId: number) => BearType | undefined;
delete: (id: number) => void;
}
export { Bear, BearType };
使用的时候
import { Bear, BearType } from "xxx";
但是依然提示
无法找到模块“xxx”的声明文件。“/xxx.cjs.js”隐式拥有 "any" 类型。
尝试使用 `npm i --save-dev @types/xx` (如果存在),或者添加一个包含 `declare module 'xxx';` 的新声明(.d.ts)文件
这个要怎么解决?手动加一个
declare module 'xxx'
有没有自动生成的?还是我自动生成的.d.ts有问题,因为里面只是把我定义的类型声明了出来,并没有这个库xxx的声明。
在 node_modules 中打开你下载下来的包, .d.ts 是否也存在?