Tuesday, 2 March 2021

Use JSDoc to reference a @class from another module

I have two JavaScript repos, libA and libB. In libB, I have a module, utilities.js:

/**
 * @class
 * @classdesc Class for doing stuff
 */
class MyClass {...}

Now in libA, I have a module, defs.js:

/**
 * @typedef {Object} UtilitiesFromB
 * @property {import("libB/utilities").MyClass} myClass - An instance of MyClass
 */

This does NOT work. However, if use @typedef on MyClass, then it does work (but I don't want to do that, since @typedef has no way of defining object methods, only properties).

/**
 * @typedef {Object} MyClass
 * @class
 * @classdesc Class for doing stuff
 */
class MyClass {...}

How do I get the type definition I created in libA/defs.js to be able to correctly reference MyClass as a property?



from Use JSDoc to reference a @class from another module

No comments:

Post a Comment