Skip to content
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

Mdx ArgsTable does not get props from TypeScript type #17029

Closed
GlebUrentsev opened this issue Dec 16, 2021 · 2 comments
Closed

Mdx ArgsTable does not get props from TypeScript type #17029

GlebUrentsev opened this issue Dec 16, 2021 · 2 comments

Comments

@GlebUrentsev
Copy link

Describe the bug

The bug connected with ArgsTable when properties are described through an interface or a type in .ts file that is imported from another module.

To Reproduce
The project uses the 6.4 version of storybook.

I published test repo to reproduce the bug
https://github.com/GlebUrentsev/TestMdxArgsTable

Just run storybook and there will be two stories of button.
The difference is that the first Button has type in the exact same file as the component, the Button2 uses type from .ts file with the same type.

Current behavior - Button2 does not have ArgsTable.

Expected behavior - Button2 has ArgsTable as Button.

@GlebUrentsev GlebUrentsev changed the title Mdx ArgsTable do not get props from TypeScript type Mdx ArgsTable does not get props from TypeScript type Dec 17, 2021
@joeycozza
Copy link
Contributor

I am digging into a similar issue, and I saw this comment on react-docgen's README. https://github.com/reactjs/react-docgen#flow-and-typescript-support

Note: react-docgen will not be able to grab the type definition if the type is imported or declared in a different file.

So for your example, I wonder if maybe react-docgen is being used instead of react-docgen-typescript. (or maybe react-docgen-typescript has the same limitation).

The ArgTypes docs here make it seem like it would infer the typescript and use react-docgen-typescript, but it isn't explicitly stated that it is smart enough to do so...

@GlebUrentsev
Copy link
Author

GlebUrentsev commented Jan 11, 2022

@joeycozza Thank you for advice! For my example the problem was fixed by installing typescript.
npm i typescript

But, digging into the problem, I found the weird case (also with type import from another file - as it was with Button2 in my example above):

If you have multiple components with displayName in the file, it breaks the ArgsTable, for example
(The problem connected with the first displayName, like it should be always in the end)

import ButtonProps from './types';

const ButtonIcon = () => <img />;
ButtonIcon.displayName = "ButtonIcon"

const Button2 = ({}: ButtonProps ) => <button><ButtonIcon  /></button>
Button2.displayName = "Button"

ArgsTable for Button will have unknown in description column. Like in that issue 15303

The problem can be solved by splitting components with displayName in different files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants