microsoft / microsoft/TypeScript

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

未关闭
#62,453 0 条评论 3 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Domain: Comment Emit Help Wanted
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

🔎 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用提供的 JavaScript/JSDoc 代码片段,通过 TypeScript v5.9.2 重现该报告,然后跟踪负责重复注释的声明生成路径。为生成的声明添加回归测试,并验证每条注释只出现一次,同时检查与 #61664 相关的行为。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。