Sunday, 11 September 2022

How to generate documentation for enum members when generating TypeScript definitions from JavaScript?

Following the official instructions in Creating .d.ts Files from .js files, I am trying to generate definitions for a JSDoc @enum.

/**
 * The direction enum.
 * 
 * @enum {number}
 */
const Direction = {
  /**
   * Up direction.
   * 
   * @type {number}
   * @constant
   */
  Up: 1,
  /**
   * Down direction.
   * 
   * @type {number}
   * @constant
   */
  Down: 2,
  /**
   * Left direction.
   * 
   * @type {number}
   * @constant
   */
  Left: 3,
  /**
   * Right direction.
   * 
   * @type {number}
   * @constant
   */
  Right: 4,
};
export default Direction;

For my tsconfig.json, I made sure that removeComments is set to false. I expect to see all the documentation for all the properties of the Direction object to carry over to the .d.ts file, however, I see the following output:

export default Direction;
/**
 * The direction enum.
 */
type Direction = number;
declare namespace Direction {
    const Up: number;
    const Down: number;
    const Left: number;
    const Right: number;
}

You can try it for yourself on the TS Playground. How can I ensure that all the documentation properly carries over?



from How to generate documentation for enum members when generating TypeScript definitions from JavaScript?

No comments:

Post a Comment