react-docgen-typescript-loader icon indicating copy to clipboard operation
react-docgen-typescript-loader copied to clipboard

Doesn't support union types

Open jeffcstock opened this issue 5 years ago • 7 comments

Consider the following:

Working, no union type

export const Button = (props: ButtonProps) => { ... }

image

Broken when union type (&) used

export const Button = (
  props: ButtonProps & React.HTMLAttributes<HTMLButtonElement>
) => { ... }

image

Any help would be much appreciated.

jeffcstock avatar Jan 10 '20 19:01 jeffcstock

The same problem is occuring to me. I'm using interface and inheritance as a workaround.

It might be cool to be able to distinguish props & extended props too.

NathanDeveloping avatar Jan 30 '20 10:01 NathanDeveloping

@NathanDeveloping I am running into this as well, can you elaborate on your workaround?

kennycrosby avatar Feb 07 '20 00:02 kennycrosby

@jeffcstock Sorry for offtop, but how you styled TS docs so beauty? :)

Where I can find info to make my docs as pretty as yours? Thanks.

YozhEzhi avatar Feb 15 '20 23:02 YozhEzhi

@YozhEzhi I believe he is using this addon: https://www.npmjs.com/package/@storybook/addon-docs

kennycrosby avatar Feb 17 '20 00:02 kennycrosby

@kennycrosby I think you're right. Thanks!

YozhEzhi avatar Feb 17 '20 07:02 YozhEzhi

@kennycrosby, with your example :

export interface ButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
// extra button props
}

export const Button: React.FunctionComponent<ButtonProps> = ({
 // props decomposed
}) => { ... }

In this way, doc generation works.

NathanDeveloping avatar Feb 17 '20 09:02 NathanDeveloping

I also have used React.FC in this case and it works

export const Button: React.FunctionComponent<ButtonProps & React.HTMLAttributes<HTMLButtonElement>> = (props) => {...}

dancingshell avatar May 15 '20 21:05 dancingshell