-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
width subtyping with nonexact known properties fails in idiomatic javascript #6146
Comments
Here the fixed example. Issues with destructuring of unions are alredy reported: https://github.com/facebook/flow/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+union+destructuring |
@apsavin that's not logically the same. In your example, E: Interesting examples: But when spreading the object, it stops working: example |
Agree, I hope it will be fixed with the ability to use destructuring of unions. |
This is actually very broken with exact types too: Try Flow There might be duplicate of this issue though. |
cc @samwgoldman, who has a lot of changes to object types in the works. |
There are a few issues here, one is a know bug with destructuring unions of objects. Here is a working version:
Once you destructure |
Thanks a lot! Definitely sounds very reasonable, but it's also surprising if you don't know exactly how Flow internals works. That's probably the reason for the confusion that's caused so many bug reports. |
@samwgoldman The solution is not ideal, especially if we wanna use flowtype to represent the proto3 oneof field. Is there any plan to improve it? |
See in try flow
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 eithertrue
orfalse
and based on that props has at least bunch of properties. If it'strue
, we know that propertya
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.
The text was updated successfully, but these errors were encountered: