Skip to content

Missing support for Flow Unions #259

Open
@millermedeiros

Description

@millermedeiros

react-docgen doesn't recognize the props if it's an union type:

type BaseProps = {|
  label: string,
|};

type LinkButtonProps = {|
  ...BaseProps,
  href: string,
  target?: string,
  rel?: string,
|};

type ButtonProps = {|
  ...BaseProps,
  type?: 'button' | 'submit',
|};

type Props = ButtonProps | LinkButtonProps;

class MyButton extends React.Component<Props> {
  render() {
     // conditionally render `<a>` or `<button>` based on props...
  }
}

I don't want users to pass props that are specific to <a> at the same time as some props that are specific to <button> - I know this kind of pattern of having a single component render to <a> or <button> is "weird", but some of our legacy components use it...

For now I need to define a single type that includes all the props and mark them all as optional - which is "fine", I guess..

More info about unions here: https://flow.org/en/docs/types/unions/

tested on v3.0.0-beta10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions