width subtyping with nonexact known properties fails in idiomatic javascript
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
See in [try flow](https://flow.org/try/#0JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQFA0wCeYWcAygK4BGAjAArFh0AXjgBvFAC44AO3YhOWKABo4nKbPmK4AXwDc9Jiw6cATPwiC4I8cimoYUYNIDmK3HYdPnO-TVwRpezYubis4AAowAVQpYz5ogEorAD44AB4AE2AANzgAemT9f0D4YxMwyOjYrjNElPSs3ILfYqCAYRIK0Ro4OFQsABssfGglHrgAOimoi1QabSlxfqGRqCkHdiwVKYm480ttOAAfMT7B4ZhoKQJkAf7tqbL99G0koWTx5YvoOAB+dLiYh2M0EhwKcCkaTKQOm0TBhSAA)
Documentation mentions width-subtyping, caveats and how to use exact types to be able to be more precise: https://flow.org/en/docs/lang/width-subtyping/
However, there are cases where all the possible types are known even when the ojbects are not exact.
As you can see, both object properties defines property `selector`. This means that the property can be either `true` or `false` and based on that props has at least bunch of properties. If it's `true`, we know that property `a` will be number, _not_ string etc.
Anyhow this is not working in flow which is major defect since the code pasted in try flow is pretty idiomatic way of using Javascript, and as far as I know, there can't be uncertainty of defined types which means it should be completely possible for Flow to type check the above code properly.
PS. the above example does not work with exact types either.
Contributor guide
Assessment
This issue has not been assessed yet.