我的项目的node_modules中有“ diagram-js”包。文件node_modules/diagram-js/lib/model/index.js
具有几个类似的类定义:
/**
* @namespace djs.model
*/
/**
* @memberOf djs.model
*/
/**
* The basic graphical representation
*
* @class
*
* @abstract
*/
export function Base() { ... }
我尝试通过以下方式使这些类可在intellisense中导入项目:
@types\diagram-js\lib\model\index.d.ts
export module 'diagram-js/lib/model' { ... }
export namespace djs.model { ... }
export declare namespace djs.model { ... }
在所有情况下,最外面的块都包含这样的类定义:
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
的文件一起使用,但是在这种情况下,Intellisense似乎找不到课程。
当前我正在使用namespace
解决方案,但是导入看起来像../../../../@types/diagram-js/lib/model
,这不是我想要的。
在我的代码库中公开这些类并获得智能感知的正确方法是什么?
答案 0 :(得分:0)
看来我要做的就是将index.d.ts
文件所在的文件夹添加到typeRoots
中的tsconfig
属性中。对于名称不是index.js
的文件,处理过程有所不同,这让我感到困惑。