-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
argTypes table is not generated for components with React.forwardRef and index type in their interface (with typescript) #15334
Comments
Same for me. There are empty props from such components. Actually, it looks like there is something related to webpack. It looks like
It seems like it's either something to fix from webpack side, or something to fix on build toolchain side from storybook. @shilman any idea where the problem is? If yes, please point me, and I'll try to help you fix it. |
Potentially, it's related to https://www.npmjs.com/package/babel-plugin-react-docgen https://github.com/storybookjs/babel-plugin-react-docgen |
I am facing the same issue, @JoyTailor-1775 can you please share the workaround that you found? |
@honohunter I'm not sure this is the exact same workaround that @JoyTailor-1775 found, but I have a workaround that sounds similar. Assuming you have a component called // Button.stories.tsx
import Button, {ButtonPropsType} from './Button';
// eslint-disable-next-line react/jsx-props-no-spreading
export const ButtonProps: React.FC<ButtonPropsType> = (props) => <Button {...props} />;
//👇 This default export determines where your story goes in the story list
export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/react/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'Components/Button',
component: ButtonProps,
args: {
children: 'Button'
}
} as ComponentMeta<typeof ButtonProps>; A few things to note here:
What this gets you is a new story under your component that lists all the props and a main entry in the Docs tab that shows the correct and complete props table. Also, stories that use the It's worth noting that wrapping the new component in // eslint-disable-next-line react/jsx-props-no-spreading
const ButtonProps: React.FC<ButtonPropsType> = (props) => <Button {...props} />;
// eslint-disable-next-line react/jsx-props-no-spreading
export const ButtonPropsStory: ComponentStory<typeof ButtonProps> = (args) => <ButtonProps {...args} />;
// …the same default export as above Hopefully this workaround helps you, and hopefully it also provides some info to anyone else about how to track down the bug that requires this workaround in the first place! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
I'm having the same problem, whenever i use |
@tupton , your solution did not work for me. |
Made a little investigation and here's what I found TL;DRWhile declaring button component, set it's type this way:
ExplanationBased on React types
Basically it means that component returned by
What TS does here is:
As long as And here's a punchline:
In our case it means that for So suggested workaround from the beginning of this answer fixes this issue. Iit simply copies return type from source code and replaces this: But it anyway looks like dirty hack, going to create an issue in |
` |
In case anyone is having trouble getting @tupon's workaround to work (or something similar to it), I found that Storybook will ignore any typings defined in the same file as the story unless the value used for
|
@umkara .,
|
please try this
|
Describe the bug
Hello, dear Storybook dev team, please take my sincere appreciation and gratitude toward the top-notch tool that you've created.
I have started using Storybook recently in my existing project and bumped into this problem right away, with the very first component. Frankly speaking, I hesitate regarding the importance of this bug, but I personally have spent around 10h trying to figure out the problem and would like to save some time for anyone else who could stumble in the same situation.
The problem is that if you have a React component wrapped in
React.forwardRef
and with index type in its interface, the arcTypes table in Storybook won't be rendered. You may see the screenshots of my code below. I've also created a repo in my GitHub, so feel free to fork it.So far, I've figured out that the issue happens only with React.forwardRef, but it's possible that some other react utilities may have the same effect.
As a workaround I also have found that if you will use
React.FC<ComponentProps>
typing for your component, this will remove the problem, even if the index type is still there.To Reproduce
Clone or fork with repository - https://github.com/JoyTailor-1775/storybook-bug
Run
npm install
andnpm run storybook
See that no doc is created for the Button component;
Go to
src/types/Button.ts
and uncomment the 54th line (with index type);Restart the project and see the doc rendered;
System
System:
OS: macOS 11.2.3
CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
Binaries:
Node: 14.16.1 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 7.18.1 - /usr/local/bin/npm
Browsers:
Chrome: 91.0.4472.114
Safari: 14.0.3
npmPackages:
@storybook/addon-actions: ^6.3.0-rc.11 => 6.3.0-rc.11
@storybook/addon-essentials: ^6.3.0-rc.11 => 6.3.0-rc.11
@storybook/addon-links: ^6.3.0-rc.11 => 6.3.0-rc.11
@storybook/builder-webpack5: ^6.3.0-rc.11 => 6.3.0-rc.11
@storybook/manager-webpack5: ^6.3.0-alpha.41 => 6.3.0-rc.11
@storybook/react: ^6.3.0-rc.11 => 6.3.0-rc.11
Additional context
The text was updated successfully, but these errors were encountered: