Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript removes JSDoc comments for overloaded functions #47228

Closed
joshuat opened this issue Dec 23, 2021 · 2 comments
Closed

TypeScript removes JSDoc comments for overloaded functions #47228

joshuat opened this issue Dec 23, 2021 · 2 comments

Comments

@joshuat
Copy link

joshuat commented Dec 23, 2021

Bug Report

TypeScript removes JSDoc comments from above overloaded functions regardless of removeComments.

🔎 Search Terms

comment; removeComments; overloaded comments;

🕗 Version & Regression Information

This is present in all versions from v3.3.3 and above, likely below as well.

⏯ Playground Link

Playground link with relevant code

💻 Code

/**
 * Missing jsDoc comment
 */
export function overloaded(
  value: number,
): number;
export function overloaded(
  value: string,
): string;
export function overloaded(
  value: number | string,
): number | string {
  if (typeof value === 'number') {
    return value * 2;
  }
  if (typeof value === 'string') {
    return value + '';
  }
}

🙁 Actual behavior

export function overloaded(value) {
    if (typeof value === 'number') {
        return value * 2;
    }
    if (typeof value === 'string') {
        return value + '';
    }
    value;
    throw new Error('Invalid value supplied');
}

🙂 Expected behavior

/**
 * Missing jsDoc comment
 */
export function overloaded(value) {
    if (typeof value === 'number') {
        return value * 2;
    }
    if (typeof value === 'string') {
        return value + '';
    }
    value;
    throw new Error('Invalid value supplied');
}
@david-shortman
Copy link

david-shortman commented Dec 23, 2021

Function overloads don't exist in JS, and the doc comments are removed. The comment is preserved when it is applied to the base method: playground

@MartinJohns
Copy link
Contributor

Duplicate of #27981. Used search terms: JSDoc overload in:title

@joshuat joshuat closed this as completed Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants