facebook / facebook/flow

Could not decide which case to select. ...

Open
#6,971 1 comment 0 reactions 0 assignees View on GitHub
Typing: unions/intersections
Dominant language
Rust
Stars
22.3k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

code ([flow.org/try/..](https://flow.org/try/#0FAFwngDgpgBAggQxgXhgb2DGBLAzgMShAGMALbAOwHMAuGAMwQBtcoAaTHAhbJqAEzqMW7TnkIlSAoc1bAAvsFCRYAIQBGKdGIJEylWjBAAnAK6is4nn0ENZFrhLLS7IhUvDQYAYWJaMlrqSBnQm5hyB+NYuYQ7ielK2wnKKnrAAIvz+Ok7k1DIiEY7RtrFF8ZIuyVDuyl7pCCBIqIgwAD4wGu0+fh2ZSvSmFMQg2AD2FEbkuADqY8YA1rgAFPyNCHQNTQCUm+valvQwq+sAdFa8AtsHWDDGRKbGkwG3kQkhRmYOrxc2oV9FH5BZy2NZNc7AxKcLCKGEwKAiG5Ye4gR7PaG3Cr6fKfcIYyIlAqsQGYyEuMEICG5AQY2EwRSKYCDYajCZTPDpMZQXAAOTGIBOTT2O2FSBeKLRSMc7xxZQxv3JZwV-BJWMSdApVISNJhtSUwCAA))

```js
type Aa = {
isFetching: false,
isFailed: false,
isFetched: false
}

type Bb = {
isFetching: true,
isFailed: false,
isFetched: false
}

type Cc = {
isFetching: true,
isFailed: true,
isFetched: false
}
type Dd = {
isFetching: false,
isFailed: true,
isFetched: false
}

type Data = Aa | Bb | Cc | Dd

function thisWorks(data: Data): Data {
if (data.isFailed) {
return {
isFetching: true,
isFailed: true,
isFetched: data.isFetched
}
} else {
return {
isFetching: true,
isFailed: false,
isFetched: data.isFetched
}
}
}

function thisDoesNot(data: Data): Data {
return {
isFetching: true,
isFailed: data.isFailed,
isFetched: data.isFetched
}
}
```

error

```
44: return {
^ Could not decide which case to select. Since case 2 [1] may work but if it doesn't case 3 [2] looks promising too. To fix add a type annotation to property `isFailed` [3].
References:
25: type Data = Aa | Bb | Cc | Dd
^ [1]
25: type Data = Aa | Bb | Cc | Dd
^ [2]
46: isFailed: data.isFailed,
^ [3]
```

this should work right?

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.