Skip to content

Fix duplicate JSDoc @typedef and @callback comments in declaration emit#62979

Closed
heathdutton wants to merge 1 commit intomicrosoft:mainfrom
heathdutton:fix-62453
Closed

Fix duplicate JSDoc @typedef and @callback comments in declaration emit#62979
heathdutton wants to merge 1 commit intomicrosoft:mainfrom
heathdutton:fix-62453

Conversation

@heathdutton
Copy link

Fixes #62453.

When emitting declaration files from JavaScript with JSDoc @typedef and @callback tags, the comments were being emitted twice: once as converted TypeScript type declarations (correct) and once as raw JSDoc comments (duplicate).

The fix skips emitting @typedef and @callback comments during declaration emit since they are already represented as type declarations.

Copilot AI review requested due to automatic review settings January 12, 2026 23:22
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jan 12, 2026
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jan 12, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where JSDoc @typedef and @callback comments were being duplicated in TypeScript declaration files. The comments were appearing both as converted TypeScript type declarations (correct) and as the original JSDoc comments (duplicate).

Changes:

  • Modified the shouldWriteComment function in the emitter to detect and skip @typedef and @callback comments during declaration emit
  • Updated baseline test files to reflect the removal of duplicate JSDoc comments

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.

File Description
src/compiler/emitter.ts Added logic to filter out @typedef and @callback comments when emitting declarations
tests/baselines/reference/*.js Updated baseline expectations to reflect removal of duplicate JSDoc comments in declaration files

// Skip @typedef and @callback comments - they're converted to type declarations
if (end !== undefined) {
const commentText = text.slice(pos, end);
if (commentText.includes("@typedef") || commentText.includes("@callback")) {
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string matching for '@typedef' and '@callback' could produce false positives if these strings appear in comment content that isn't actually a typedef or callback declaration (e.g., in documentation text or code examples). Consider using a more precise pattern match that checks for these tags at word boundaries, such as matching /@typedef\b/ and /@callback\b/ to ensure they are actual JSDoc tags.

Suggested change
if (commentText.includes("@typedef") || commentText.includes("@callback")) {
if (/@typedef\b/.test(commentText) || /@callback\b/.test(commentText)) {

Copilot uses AI. Check for mistakes.
Comment on lines +6002 to +6005
const commentText = text.slice(pos, end);
if (commentText.includes("@typedef") || commentText.includes("@callback")) {
return false;
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a substring via slice() for every comment during emit could impact performance when processing files with many comments. Consider checking for the presence of '@typedef' or '@callback' using indexOf() with boundary checks on the original string instead of creating a new substring.

Suggested change
const commentText = text.slice(pos, end);
if (commentText.includes("@typedef") || commentText.includes("@callback")) {
return false;
}
const typedefIndex = text.indexOf("@typedef", pos);
if (typedefIndex !== -1 && typedefIndex < end) {
return false;
}
const callbackIndex = text.indexOf("@callback", pos);
if (callbackIndex !== -1 && callbackIndex < end) {
return false;
}

Copilot uses AI. Check for mistakes.
@heathdutton
Copy link
Author

Both suggestions would deviate from existing codebase conventions, but happy to make a change if a human replies.

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
@typescript-bot
Copy link
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

3 participants