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

Implicitly typed `props` in FunctionComponent not found

Open brandongregoryscott opened this issue 3 years ago • 1 comments

Given the following component structure:

import React from "react";

interface ButtonProps {
  onClick: () => void;
}

const Button: React.FC<ButtonProps> = (props) => {
  return <button {...props}>Hello world</button>;
};

export default Button;

react-docgen returns an object without any props:

{
  "description": "",
  "displayName": "Button",
  "methods": []
}

However, if props is explicitly typed, the expected props are returned:

const Button: React.FC<ButtonProps> = (props: ButtonProps) => {
{
  "description": "",
  "displayName": "Button",
  "methods": [],
  "props": {
    "onClick": {
      "required": true,
      "tsType": {
        "name": "signature",
        "type": "function",
        "raw": "() => void",
        "signature": {
          "arguments": [],
          "return": {
            "name": "void"
          }
        }
      },
      "description": ""
    }
  }
}

Given that TypeScript properly detects props as ButtonProps without the explicit typing (pulled from React.FC<ButtonProps> type of the component itself), it feels like this shouldn't be a required case to parse props correctly. Is there any easy way to tweak the existing resolver to read the generic type of React.FC?

brandongregoryscott avatar May 04 '22 21:05 brandongregoryscott

Thanks for reporting. You are right that this totally should work. We will have a look soon.

danez avatar May 05 '22 09:05 danez

Can you describe how to attack this problem? I'd like to try working on a PR.

thasmin avatar Apr 26 '23 12:04 thasmin

Fixed in 7.0

danez avatar Oct 19 '23 15:10 danez