Skip to content

Support ~ namespace qualifier in JS Doc type positions #47199

@djipco

Description

@djipco

Bug Report

I'm using tsc to create a .d.ts file from jsdoc comments in my JavaScript source files. When I scope a custom type definition using the "~" character, if the parameter is optional, it will not be in the outputted .d.ts.

According to jsdoc documentation, this is the correct way to scope a callback to a specific class.

💻 Code

JavaScript source:

class Test {

  /**
   * @callback Test~myCallback
   * @param {string} [name] Event name
   */

  /**
   * @method
   * @param {string} [event] Event name.
   * @param {Test~myCallback} [callback] The callback
   */
  removeListener(event, callback) {
  
  }

}

Outputted .d.ts file:

declare class Test {
  removeListener(event?: string, callback: any): void;
}

🙁 Actual behaviour

The output renders "callback" as if mandatory. This is invalid as a mandatory parameter cannot follow an optional one. Also, the type is "any", event though I defined a custom type.

🙂 Expected behaviour

The "callback" parameter should be optional as specified in the source JavaScript. The type should be "Test~myCallback" (or however TypeScript deals with these).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions