1

My project has the package "diagram-js" in its node_modules. The file node_modules/diagram-js/lib/model/index.js has several class definitions like this:

/**
 * @namespace djs.model
 */

/**
 * @memberOf djs.model
 */

/**
 * The basic graphical representation
 *
 * @class
 *
 * @abstract
 */
export function Base() { ... }

I've tried making these classes importable in my project with intellisense in the following way:

  1. created the file @types\diagram-js\lib\model\index.d.ts
  2. tried any of the following syntaxes:
export module 'diagram-js/lib/model' { ... }
export namespace djs.model { ... }
export declare namespace djs.model { ... }

in all cases the outermost block contains 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've also tried declare module and within it export class, but while this worked with other files that weren't index.js, in this case intellisense can't seem to find these classes.

Currently I'm using the namespace solution but the imports look like ../../../../@types/diagram-js/lib/model which is not what I want.

What's the right way to expose these classes in my codebase and get intellisense?

1 Answer 1

1

It looks like all I needed to do was add the folder the index.d.ts file was in to the typeRoots property in tsconfig. For files with names other than index.js the process is different, which is what confused me.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.