otris / jsdoc-tsd

JSDoc template for generating TypeScript definition files based on JSDoc comments.
MIT License
29 stars 7 forks source link

Are ES 2015 Classes not supported? #80

Closed borgar closed 1 year ago

borgar commented 1 year ago

I'm running jsdoc-tsd version 3.0.0 and jsdoc version 4.0.2. Command is simply jsdoc -t node_modules/@otris/jsdoc-tsd Node.js

I have a class file that can be reduced to this:

/**
 * @property {string} value The value of the node.
 */
export class Node {
  constructor (value = '') {
    this.value = value;
  }
}

Which only yields an error: "Can't add member 'Node' to parent item 'Node'. Unsupported member type: 'class'".

Same thing with the ES 2015 Classes example in the JSDoc documentation.

I've been able to get rid of the error by tagging with @class and @constructs, but that still doesn't give me any output.

wehrstedt commented 1 year ago

That's because you are not writing valid jsdoc. jsdoc-tsd is nothing else than a simple plugin for jsdoc. Except it is more strict and throws errors instead of just supressing the error (like other plugins). So when this plugin throws an error, your are either not writing valid jsdoc, or the plugin has a bug (or doesn't support the input). In your case, you are trying to document a constructor parameter and the input should be:

export class Node {
  /**
   * @param {string} value The value of the node.
   */
  constructor (value = '') {
    this.value = value;
  }
}

There is a simple tip with which you can check if you made anything wrong: Just check if your input appears in the generated html documentation (which will be generated by omitting -t node_modules/@otris/jsdoc-tsd). If your input does not appear, you are not writing valid jsdoc. Otherwise its likely a bug (or not supported).

borgar commented 1 year ago

you are not writing valid jsdoc [...] you are trying to document a constructor parameter

I think this is a misreading of that I have posted, so I'll clarify.

The example is documenting a class with a single property (it has been reduced for brevity). From what I can see, the code is perfectly valid and it works fine in JSDoc. Here is a screenshot of the JSDoc output I'm getting:

Screen Shot 2023-06-29 at 10 59 08

Therefore I would expect the output from this to be:

/**
 * @property {string} value The value of the node.
 */
export class Node {
  value: string;
}

Again, an example from the JSDoc documentation has the exact same issue, so this does not seem like it is tied to my code specifically.

borgar commented 1 year ago

I've had some time with this and will open a new issue that is more accurate.