【发布时间】:2020-11-10 23:20:40
【问题描述】:
我的项目中有 JS/TS 代码库。一些文件看起来像:
import Something from '@some-lib/things/something'; // index.jsx file here
const someFunction = () => {
// do something with "Something"
};
在 VS Code 和 tsc 结果中我有错误:
找不到模块的声明文件 '@some-lib/things/something'。
'/Users/user/Projects/project/node_modules/@some-lib/things/something/index.jsx' 隐式具有“任何”类型。
尝试
npm install ...(如果存在)或添加新声明 (.d.ts) 包含declare module '@some-lib/things/something';的文件
我尝试通过 creatig 文件 src/@types/@some-lib/index.d.ts 使用以下内容添加定义:
declare module '@some-lib/things/something' {
const Something: (props: React.SVGProps<SVGSVGElement> & {
size?: number,
color?: string,
inline?: boolean,
className?: string,
}) => React.ReactElement;
export default Icon;
}
但我得到这个错误:
扩充中的模块名称无效。
模块“@some-lib/things/something”解析为“/Users/user/Projects/project/node_modules/@some-lib/things/something/index.jsx”处的无类型模块,无法扩展。
请帮帮我。如何从带有子目录/子模块的 npm 声明 JS 库的 TypeScript 类型?
【问题讨论】:
标签: javascript node.js reactjs typescript npm