Flow cannot distinguish method signature in disjoint union
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Working example: https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoALgTwA4FMwDKAlgHYDmMuAKmALxgDeqYYAtgK4zpHaUBcYKAEMYAZ1wAaZmDgkAwgAsh5XAIAUANxHtVYUegBOpMgEo6APjAa4RACaoAvqgw58AWU7ca9Jiw5cefjBDHSkWWUVlMl1NbV0AQQMDIUwAHn0jcnMzWktrO0dnLDwwAAUDOGxRb0JjShoAHzAPAKpnVCh2EgBjblkwAFVeOCFbNQY2T0DJGXklFTAHAXLK6rMmAEgiKDV-bl58WiPggx111A3wuajcNQBtAHIoODgHiTAHgCMhAweAXRM0hYDjAuDE+F8LChEXm0TUTxe31+gKhi0KQA
I wonder why the following code is not type-checking. As far as I've understood disjoint unions the `multiple` property should tell Flow what to expect as `onChange`. However, this doesn't seem to work. I'd like to understand whether this is my fault and how I could get this to type check or whether this is a bug.
**Code**
```es6
/* @flow */
type SingleT = {
multiple: false,
onChange: (value: string) => void
}
type MultiT = {
multiple: true,
onChange: (value: Array) => void
}
type PropsT = SingleT | MultiT
function Upload({ multiple, onChange }: PropsT) {
if(multiple === true) {
onChange(['foo', 'bar'])
} else {
onChange('foobar')
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.