reactjs / react-docgen

A CLI and library to extract information from React component files for documentation generation purposes.

Home Page:https://react-docgen.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeScript: Missing Union Elements of Indexed Access Type

fujikky opened this issue · comments

Hello there,
In the following code, the elements of the size props are not outputted.

type Base = {
  size: "small" | "medium" | "large";  
};

type Props = {
  size: Base["size"];
}

const MyComponent = ({size}: Props) => {
  return <div />;
}

Result

[
  {
    "description": "",
    "displayName": "MyComponent",
    "methods": [],
    "props": {
      "size": {
        "required": true,
        "tsType": {
          "name": "union",
          "raw": "Base[\"size\"]"
        },
        "description": ""
      }
    }
  }
]

Expected Behavior

[
  {
    "description": "",
    "displayName": "MyComponent",
    "methods": [],
    "props": {
      "size": {
        "required": true,
        "tsType": {
          "name": "union",
          "raw": "\"small\" | \"medium\" | \"large\"",
          "elements": [
            {
              "name": "literal",
              "value": "\"small\""
            },
            {
              "name": "literal",
              "value": "\"medium\""
            },
            {
              "name": "literal",
              "value": "\"large\""
            }
          ]
        },
        "description": ""
      }
    }
  }
]

I reproduced it here:
https://react-docgen.dev/playground

Thanks for regards.