Skip to content

Question: Import typedef from another file? #1537

@Legends

Description

@Legends

I need a common place where I can import the typedef from, in order to not define the type Position in other used modules over and over again?

Is it possible to have a common file like common-type-defs.js,
where I can define `typedef``s for objects which actually don't have a type implementation in form of a class?

For example I have a typedef Position which I want to reuse in different modules:

/** @typedef {Object} Position
 *  @property {number} column
 *  @property {number} line
 */

/** @typedef {Object} Loc
 *  @property {Position} start
 *  @property {Position} end
 */

common-type-defs.js

/** @typedef {Object} Position
 *  @property {number} column
 *  @property {number} line
 */

/** @typedef {Object} Loc
 *  @property {Position} start
 *  @property {Position} end
 */

I need a common place where I can import the typedef from, in order to not define the type Position again?
Or do I have to create a common-types.js file with an implementation of Position and then imort it, like:
/** @typedef {import("./common-types.js").Position} Position*/

or reference typedef
file1.js

 @reference typedef Position from `common-type-defs.js`  // dummy code

Class XYZ{

   @type {Position} position
   constructor(position){
    ...
   }
}

Your environment

Software Version
JSDoc ?
Node.js 8.11.3
npm 5.8.0
Operating system Win 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions