I have the following project structure:
api/
users/
users.d.js
contexts/
users/
users.d.js
utils/
users/
users.d.js
In utils/users/users.d.js I am defining the types that are reusable through the whole system.
For example, the following type:
/**
* Represents a User.
*
* @typedef {object} User
* @property {string} id - Unique identifier.
* …
* @property {Date} birthday - Birthday.
*/
This is cool, now I can reuse it in my module index.js as follows:
import “./utils/users/users.d”;
/**
* …
* @param {User} user - The profile owner.
*/
function navigateToUserProfile(user) {
…
}
And that works fine! My code editor detects the type and the documentation can be auto generated without problems :)
But… what if api/users/users.d.js requires that global type definition?
For example, what if in that module I have the following definition:
/**
* @typedef {object} EditProfileInterface
*
* @property {User} newUserData - The new user data.
* …
*/
In order to reuse the global definition, I would need to import the utility module (utils/users/users.d.js) in the “local type definitions” module (api/users/users.d.js).
Okey… so, let just do:
// this code is inside api/users/users.d.js
import “../../utils/users/users.d”;
as we did inside index.js.
Here is where my problem comes. After doing this, JSDOC is not able to generate the documentation correctly any more. It moves the type definitions of api/users/users.d.js to the global section of the documentation.
Also, if I do // @ts-check
inside a module that imports api/users/users.d.js, I get the error Cannot find name ‘EditProfileInterface’ (unresolved type). This is making really difficult the types reusability… it seems that there is no more options than duplicating the definitions between modules (?)
Any suggestions or workarounds? Should I just don’t care about duplicating type definitions between different modules?
export {}
, to avoid linting errors. – Bowyer