Missing support for Flow Unions
See original GitHub issuereact-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
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Union Types - JavaScript. Flow
With union types in Flow you can “refine” the value down to a single type. For example, if we have a value with...
Read more >Flow union type with exact object types gives 'property is ...
Flow union type with exact object types gives 'property is missing ... branch indicates that the properties are missing on one of the...
Read more >Solved: Union function missing from function list
This is a screen shot of my flow and the error when trying to find union in the functions list. Solved!
Read more >Union Type missing properties · Issue #5983 · facebook/flow
Resulting in the following flow exception: Cannot get message.labelName because: • all branches are incompatible: • Either property labelName is ...
Read more >Making union types even more useful - Scala Contributors
Specifically, the flow typing support for Explicit Null, ... Of course, Union Types in general would probably benefit a lot from wider ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d assume OP is talking about missing descriptions.
With
I automatically receive a description containing all possible enum values.
With FlowType and its unions (i e
type?: "animal" | "bacon"
, no such description is generated.I’m using react styleguidist, btw.
Like @Happy-Ferret said, I think the
PropTypes.oneOf([ ... ])
-equivalent for Flow would be closest to ideal here.