react-docgen icon indicating copy to clipboard operation
react-docgen copied to clipboard

Cannot get comment under object in TypeScript

Open xiaoshuangLi opened this issue 3 years ago • 1 comments

The shape is Object, the comment of shape.string and shape.number don't work.

// [email protected]

const code = `
  import React from 'react';
  import PropTypes from 'prop-types';

  type Props = {
    /**
     * shape
     */
    shape: {
      /**
       * string
       */
      string: string;
      /**
       * number
       */
      number: number;
    };
  };

  class TSReactComponent extends Component<Props> {
    render() {
      return (
        <div {...this.props} />
      );
    }
  }

  export default TSReactComponent;
`;


const result = parse(code) || {};

/** 
 * result ==> json
 *
 * shape.string doesn't have description, should be { "description": "string" }
 * shape.number doesn't have description, should be { "description": "number" }
 */
const json = {
  "props": {
    "shape": {
      "required": true,
      "tsType": {
        "name": "signature",
        "type": "object",
        "raw": "{\n  /**\n   * string\n   */\n  string: string;\n  /**\n   * number\n   */\n  number: number;\n}",
        "signature": {
          "properties": [{
            "key": "string",
            "value": {
              "name": "string",
              "required": true
            }
          }, {
            "key": "number",
            "value": {
              "name": "number",
              "required": true
            }
          }]
        }
      },
      "description": "shape"
    }
  }
};

xiaoshuangLi avatar Feb 26 '21 08:02 xiaoshuangLi

I've faced the same problem.

interface MainOptions {
  /** If set to true video will start on load. */
  autoplay: boolean;
  /** If set to true video will repeat after end */
  repeat: boolean;
}
interface props {
  /** Main options of the player */
  options: Partial<MainOptions>;
}

But I don't get any description for autoplay and repeat params. Any solutions?

hosseini44444 avatar Jul 21 '21 20:07 hosseini44444