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

JSDocs comments being removed while autogenerating a .d.ts file for a const JavaScript namespace #46010

Open
PSYmoom opened this issue Sep 22, 2021 · 3 comments
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling
Milestone

Comments

@PSYmoom
Copy link

PSYmoom commented Sep 22, 2021

Bug Report

I am currently trying to autogenerate .d.ts files for my JavaScript API using --declaration and I am running into problems. All of the files which use a const namespace will have all of their comments removed, including the JSDocs ones. I have set removeComments as false in tsconfig and sanity checked it by a class with comments and all of the comments were retained in the class, but not the namespace.

🔎 Search Terms

Duplicate methods --declaration
namespace .d.ts bug

🕗 Version & Regression Information

4.4.3 but happens with any 4.x.x version I've tried (haven't tried earlier versions).

⏯ Playground Link

The Playground was not playing nicely with emitDeclaration and filenames with .js extension

💻 Code

/**
 * Foo namespace
 * @namespace
 */
const Foo = {
    /** Test function */
    foo: function() {},
    /** Test property */
    bar: 1
}

🙁 Actual behavior

declare namespace Foo {
    function foo(): void;
    const bar: number;
}

🙂 Expected behavior

 /**
  * Foo namespace
  * @namespace
  */
 declare namespace Foo {
    /** Test function */
    function foo(): void;
    /** Test property */
    const bar: number;
 }

@andrewbranch andrewbranch added Domain: Comment Emit The issue relates to the emission of comments when compiling Needs Investigation This issue needs a team member to investigate its status. Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Sep 23, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Sep 23, 2021
@sanjeetsuhag
Copy link

sanjeetsuhag commented Sep 7, 2022

We're running into this issue too. A simple enum example


/**
 * The direction enum.
 * 
 * @enum {number}
 */
enum Direction {
  /**
   * Up direction.
   * 
   * @type {number}
   */
  Up = 1,
  /**
   * Down direction.
   * 
   * @type {number}
   */
  Down = 2,
  /**
   * Left direction.
   * 
   * @type {number}
   */
  Left = 3,
  /**
   * Right direction.
   * 
   * @type {number}
   */
  Right = 4,
}
export default Direction;

generates the following output:

export default Direction;
/**
 * The direction enum.
 */
type Direction = number;
declare namespace Direction {
    const Up: number;
    const Down: number;
    const Left: number;
    const Right: number;
}

TS Playground link.

@Artxe2
Copy link

Artxe2 commented Oct 12, 2023

This problem is still occurring.
Is there no work scheduled for this?

// js source

/**
 * default
 * @param {number} param
 */
export default param => {
  /**
   * default.result
   * @param {string} p
   */
  const result = p => p + p

  /**
   * default.result.fn
   */
  result.fn = () => {}
  return result
}
// generated d.ts

declare function _default(param: number): {
    (p: string): string;
    /**
     * default.result.fn
     */
    fn(): void;
};
export default _default;

Playground

@chuacw
Copy link

chuacw commented Oct 22, 2024

Encountering this as well.
JSDoc should be preserved, irrespective of removeComments setting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Comment Emit The issue relates to the emission of comments when compiling
Projects
None yet
Development

No branches or pull requests

5 participants