reactjs / reactjs/react-docgen

Missing support for Flow Unions

Open
#259 5 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
3.8k
Forks
316
Avg merge
5h 7m
Merged PRs (30d)
4

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example from the issue using react-docgen v3.0.0-beta10 and compare the result with the expected props for the union. Read the linked Flow unions documentation and trace the parser entry point that handles component props. Done means union members are recognized without requiring users to flatten all props into one optional type.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
devtools, documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.