In my project, I have the package called "diagram-js" in the node_modules. The file
node_modules/diagram-js/lib/model/index.js
contains multiple class definitions as shown below:
/**
* @namespace djs.model
*/
/**
* @memberOf djs.model
*/
/**
* The basic graphical representation
*
* @class
*
* @abstract
*/
export function Base() { ... }
I attempted to make these classes importable in my project with intellisense using the steps outlined below:
- Created a file called
@types\diagram-js\lib\model\index.d.ts
- Used various syntaxes such as:
export module 'diagram-js/lib/model' { ... }
export namespace djs.model { ... }
export declare namespace djs.model { ... }
In all scenarios, the outermost block contained the class definitions like this:
declare class Base {
id: string;
type: string;
businessObject: any;
label: Object;
parent: Shape;
labels: Array<Label>;
outgoing: Array<Connection>;
incoming: Array<Connection>;
}
I also experimented with using declare module
and within it declaring export class
. This method worked for other files, but not for index.js
, as intellisense could not identify those classes.
Currently, I am utilizing the namespace
solution, however, the imports appear as
../../../../@types/diagram-js/lib/model
, which is not ideal. What would be the correct approach to expose these classes in my codebase and enable intellisense?