Automatic argTypes if component TypeScript prop types are imported #34477
Replies: 2 comments
-
|
Hi @martynhoyer! I'm Dosu and I’m helping the storybook team. This is a limitation of the default Switching to const config: StorybookConfig = {
// ...
typescript: {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
shouldRemoveUndefinedFromOptional: true,
},
},
};The trade-off is speed — Give that a try and see if your To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
Thought the AI was on to something there, but unfortunately not. We're already using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Hi!
I've got some components which import their types from a shared types file because the same types are used throughout the codebase in different components. Here's a reduced example of a component with a
statusprop, which is limited to three potential options;"inProgress" | "completed" | "deleted"You can see in
HeaderCardProps, thestatusprop's value is imported from a shared file.When I create a Storybook story for that component and use Autodocs, I'd expect the props table to give me those three options as a
<select>or radio buttons, but instead, it gives me a string. This is what my story code looks like:And here's a screenshot of the props table in Storybook for that story:
If I remove the imported type and hard code the values instead, like this
interface HeaderCardProps { - status: Status; + status: "inProgress" | "deleted" | "completed"; }Then Storybook updates and gives me something more like what I'm after:
Although of course, the "description" column is missing the type name now.
Am I missing something, or is this a limitation of Storybook?
I'm assuming I can use the argTypes object to override it at a story level, but to me that seems to defeat the object of the autodocs feature, and gives me quite a lot more admin when creating Storybook stories.
Any assistance is greatly appreciated!
Additional information
I'm running the following versions (upgrading is possible, but organisationally challenging):
Storybook 9.1.1
React 16 🙄
Webpack 5
Create a reproduction
No response
Beta Was this translation helpful? Give feedback.
All reactions