![](/img/trans.png)
[英]ERROR in ./src/index.js Module build failed (from ./node_modules/babel-loader/lib/index.js):
[英]import class definitions from node_modules index.js
我的项目在其 node_modules 中有 package “diagram-js”。 文件node_modules/diagram-js/lib/model/index.js
有几个 class 定义,如下所示:
/**
* @namespace djs.model
*/
/**
* @memberOf djs.model
*/
/**
* The basic graphical representation
*
* @class
*
* @abstract
*/
export function Base() { ... }
我尝试通过以下方式使用智能感知使这些类在我的项目中可导入:
@types\diagram-js\lib\model\index.d.ts
export module 'diagram-js/lib/model' { ... }
export namespace djs.model { ... }
export declare namespace djs.model { ... }
在所有情况下,最外面的块都包含 class 定义,如下所示:
declare class Base {
id: string;
type: string;
businessObject: any;
label: Object;
parent: Shape;
labels: Array<Label>;
outgoing: Array<Connection>;
incoming: Array<Connection>;
}
我也尝试过declare module
并在其中export class
,但是虽然这适用于其他不是index.js
的文件,但在这种情况下,智能感知似乎找不到这些类。
目前我正在使用namespace
解决方案,但导入看起来像../../../../@types/diagram-js/lib/model
这不是我想要的。
在我的代码库中公开这些类并获得智能感知的正确方法是什么?
看起来我需要做的就是将index.d.ts
文件所在的文件夹添加到tsconfig
的typeRoots
属性中。 对于名称不是index.js
的文件,过程是不同的,这让我感到困惑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.