【发布时间】:2018-09-28 05:57:54
【问题描述】:
我想将类型添加到纯粹用 Javascript 编写的组件库中,我目前无法直接添加到该组件库中。我已经按照adding declarations to third party packages 的这个示例进行操作,这几乎让我到达了那里。我目前遇到的问题是包结构。
该包位于node_modules 和@company/company-widgets,我不确定如何处理内部模块,因为tsc 无法找到并关联我添加的声明文件。编译器的建议是
Try `npm install @types/company__company-widgets` if it exists or add a new declaration (.d.ts) file containing `declare module 'company__company-widgets';`
我尝试了以下方法:
- 使用编译器消息中指定的模块声明修改
tsconfig.json和"typeRoots": ["@types", "./src/@types"] and adding anindex.d.ts` 文件 - 随着上述
tsconfig.json的更改,在src/@types下添加目录以匹配node_modules的目录 - 我还将声明更改为具有名为 company 的
module和 __company-widgets 的namespace - 我也很绝望,并开始在
node_modules中添加声明来搞乱
不幸的是,这些都没有找到声明,所以我一直认为它无法将声明中的模块名称与包名称相关联。 任何建议或答案将不胜感激。谢谢!
【问题讨论】:
标签: typescript tsc