Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JSDoc comments emitted a second time even after commenrs on type are emittedΒ #62453

@CxRes

Description

@CxRes

πŸ”Ž Search Terms

JSDoc, emit, comments

πŸ•— Version & Regression Information

v5.9.2

  • I was unable to test this on prior versions because I was not using TS.

⏯ Playground Link

No response

πŸ’» Code

/**
 * The template passed to generate messages
 *
 * @callback Template
 * @param {...*} args - Arguments to the template
 * @returns {any} The generated message
 */

/**
 * The arguments sent with notify become the input parameters for the template.
 *
 * @typedef {Parameters<Template>} TemplateParams
 */

/**
 * The return value from the template is yielded as the message generated from
 * the subscription. The following types help define this relationship.
 *
 * @typedef {ReturnType<Template>} Message
 */

πŸ™ Actual behavior

Typescript, when emitting from JSDoc, seems to want to emit the same comments for a type declaration twice:

  • once for the export (good) and
  • once just copying over the JSDoc comment (bad).
/**
 * The template passed to generate messages
 */
export type Template = (...args: any[]) => any;
/**
 * The arguments sent with notify become the input parameters for the template.
 */
export type TemplateParams = Parameters<Template>;
/**
 * The return value from the template is yielded as the message generated from
 * the subscription. The following types help define this relationship.
 */
export type Message = ReturnType<Template>;
/**
 * The template passed to generate messages
 *
 * @callback Template
 * @param {...*} args Arguments to the template
 * @returns {any} The generated message
 */
/**
 * The arguments sent with notify become the input parameters for the template.
 *
 * @typedef {Parameters<Template>} TemplateParams
 */
/**
 * The return value from the template is yielded as the message generated from
 * the subscription. The following types help define this relationship.
 *
 * @typedef {ReturnType<Template>} Message
 */

πŸ™‚ Expected behavior

It should emit the comment just once:

/**
 * The template passed to generate messages
 */
export type Template = (...args: any[]) => any;
/**
 * The arguments sent with notify become the input parameters for the template.
 */
export type TemplateParams = Parameters<Template>;
/**
 * The return value from the template is yielded as the message generated from
 * the subscription. The following types help define this relationship.
 */
export type Message = ReturnType<Template>;

or even better (See #61664)

/**
 * The template passed to generate messages
 *
 * @param Arguments to the template
 * @returns The generated message
 */
export type Template = (...args: any[]) => any;
/**
 * The arguments sent with notify become the input parameters for the template.
 */
export type TemplateParams = Parameters<Template>;
/**
 * The return value from the template is yielded as the message generated from
 * the subscription. The following types help define this relationship.
 */
export type Message = ReturnType<Template>;

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions