Skip to content

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.
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: Not started

Development

Successfully merging this pull request may close these issues.

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

2 participants