Reporting from https://github.com/storybookjs/storybook/pull/24165 Currently TS enums analysis is lossy: ```tsx enum ButtonType { Button = 'button', Reset = 'reset', Submit = 'submit', } type ButtonTestProps = { type?: ButtonType; }; export const ButtonTest = (props: ButtonTestProps) => { return <button {...props}>Test</button>; }; ``` Produces: ```json "tsType": { "name": "ButtonType" }, ``` Compare this to a union: ```ts type ButtonType = "button" | "reset" | "submit"; ``` Which produces: ```json "tsType": { "name": "union", "raw": "\"button\" | \"reset\" | \"submit\"", "elements": [ { "name": "literal", "value": "\"button\"" }, { "name": "literal", "value": "\"reset\"" }, { "name": "literal", "value": "\"submit\"" } ] }, ``` It would be fantastic if `react-docgen` could produce something similar for enums!
Activity
rvetere commentedon May 14, 2024
I believe this is not the case anymore...? When i test enums in our project, i got this output:
the typescript type looks like this:
kasperpeulen commentedon Jun 14, 2024
@shilman maybe this is actually a storybook integration problem instead. It seems that the enum is available.
cc @valentinpalkovic
jtiala commentedon Nov 12, 2024
That prop is not an enum but a string literal union.
Docgen doesn't work for enums or string literal tuples with const assertion:
{ "example.tsx": [ { "description": "Example", "methods": [], "displayName": "Example", "props": { "unionProp": { "required": false, "tsType": { "name": "union", "raw": "\"cat\" | \"dog\"", "elements": [ { "name": "literal", "value": "\"cat\"" }, { "name": "literal", "value": "\"dog\"" } ] }, "description": "String literal union.", "defaultValue": { "value": "\"cat\"", "computed": false } }, "tupleProp": { "required": false, "tsType": { "name": "petTupleValues[number]", "raw": "PetTuple[number]" }, "description": "Tuple of string literals with const assertion.", "defaultValue": { "value": "\"cat\"", "computed": false } }, "enumProp": { "required": false, "tsType": { "name": "PetEnum" }, "description": "Enum.", "defaultValue": { "value": "PetEnum.CAT", "computed": true } } } } ] }Reproduction in Storybook here.
react-docgen-typescriptanalyses all of these three cases correctly.