facebook / facebook/flow

Disjoint union type for React props does not work.

Open
#7,623 0 comments 0 reactions 0 assignees View on GitHub
bug Typing: completeness
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Flow version: 0.96.1

```js
import * as React from 'react';

export type TextPropsType =
| {|
theme: 'black',
size: 'h800'
|}
| {|
theme: 'black',
size: 'h700'
|};

class Test extends React.Component {};

declare var isMobile: boolean;

const textSize = isMobile ? "h700" : "h800";

const rendered3 = ;
```

## Expected behavior

No errors

## Actual behavior

```
Cannot create `Test` element because: Either string [1] is incompatible with string literal `h800` [2] in property `size`. Or string [3] is incompatible with string literal `h700` [4] in property `size`.
```

* Link to Try-Flow or Github repo: https://flow.org/try/#0JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdWAHpLHDAJ5hZwAqzMAArEwqXlx4BeOHQA+cAN6y6cVapgALLCCwAucgCMANngDWZADQq1cVMABee8hoAcABjdlrsgL5zFyjbsWjr6ZMZmltZqdo5hGgDsHl6qvvR0uCao6Pyo8AJYAHYAJujYeDAAdADCJJCFRTAAPPxMQiJiEgB8ij7pxViZyJRwAG7DcMCoALIQBsBGTgYQEIvIhem4EIV57AIAyg5SkzNzCzwA-HAARIke13D6t+5u15vbu5QlWJTFAMxwaQtLC7TTaLCSa4RXCmB6xCEKGAHI4+OAAei69CAA

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.