Inconsistency when destructuring union types
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Flow may produce `missing property` errors when destructing a union type in a function signature, but not if the destructuring occurs within the function body. This feels inconsistent. Is this the expected behavior, and if so, what is Flow trying to protect against?
Destructing in function signature example [here](https://flow.org/try/#0C4TwDgpgBAggxsAlgewHYygXigbwD5QCGCKqAqmQJIAiAXFAM7ABOiqA5gDRRzICuqYPVR8AtgCMIzKHgC+AbgBQoSLBJoAQllwFiSNBRr0mrDt0QMAYsmT1xNgDYRCqGQsXLw0ACpeAsoRg2jiKAJAw9CFQ0TFghMyEogz08PronIoxULIZ0aEakZlZUHEJSSnqqBq5MTmK7p6qACSppAAK8YkAPG30TQDSECAMXb6QAWAAfJPBRaEA1HEgDsiEACaFoaEAdLtNbczIkMygYxBdTQCiTqIQgmej-oHcbZPcAOSliQzvb2Gy9SUil4qCYsG07xg7yUILBWmw7w00I8ADMBJUSqZgK0DFRqAAKHBLFbrWR9HGoDplLoqCDIFHggi0+lQDSTACUuCKsOQTm2K3Y+OJqzW2z0pEM1HZ8ig9SAA):
```
function printActionUUID({payload}: $ActionParam) {
console.log(payload.actionUUID);
}
```
which produces the following errors:
```
22: function printActionUUID({payload}: $ActionParam) {
^ property `count` is missing in `ActionB` [1] but exists in `ActionA` [2].
References:
9: params: ActionB,
^ [1]
6: params: ActionA,
^ [2]
22: function printActionUUID({payload}: $ActionParam) {
^ property `isFoo` is missing in `ActionA` [1] but exists in `ActionB` [2].
References:
6: params: ActionA,
^ [1]
9: params: ActionB,
^ [2]
```
In contrast, the following produces no errors ([link](https://flow.org/try/#0C4TwDgpgBAggxsAlgewHYygXigbwD5QCGCKqAqmQJIAiAXFAM7ABOiqA5gDRRzICuqYPVR8AtgCMIzKHgC+AbgBQoSLBJoAQllwFiSNBRr0mrDt0QMAYsmT1xNgDYRCqGQsXLw0ACpeAsoRg2jiKAJAw9CFQ0TFghMyEogz08PronIoxULIZ0aEakZlZUHEJSSnqqBq5MTmK7p6qACSppAAK8YkAPG30TQDSECAMXb6QAWAAfJPBRaEA1HEgDsiEACaFoaEAdLtNbczIkMygYxBdTQCiTqIQgmej-oHcbZPcAOSliQzvb2Gy9SUil4qCYsG07xg7yUILBWmw7w00I8ADMBJUSqZgK0DFRqAAKPSkPo41AdMpdFQQZAo8EEKk0qAaSYASlwRVhwFwSxW61k2iJaCU0VhyCc2xW7HxPNWa22gvIeJZ8ig9SAA)):
```
function printActionUUID(action: $ActionParam) {
const {payload} = action;
console.log(payload.actionUUID);
}
```
Contributor guide
Assessment
This issue has not been assessed yet.