Skip to content

TypeScript: Missing Union Elements of Indexed Access Type #906

Open
@fujikky

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions