Skip to content
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

Intersection of object types should be a valid lower bound of the object type with properties from all branches #1327

Closed
samwgoldman opened this issue Jan 28, 2016 · 1 comment

Comments

@samwgoldman
Copy link
Member

Repro:

/* @flow */
type A = { a: string } & { b: string };
type B = { a: string, b: string };
declare var a: A;
var b: B = a;
test.js:5
  5: var b: B = a;
                ^ intersection: object type(s). This type is incompatible with
  5: var b: B = a;
            ^ object type

What's happening here, as far as I can tell, is that Flow tries both branches of the intersection in A one at a time. As if we assigned var b: B = { a: string } then later var b: B = { b: string }. Both of these assignments independently should fail, but if we imagined that both assignments happened "together" should succeed.

I think that lots of issues related to intersection types might reduce to this. Check out linked issues for more examples.

@pasha-mf
Copy link
Contributor

Seems like #1172 is related.

@samwgoldman samwgoldman changed the title Intersection of object type should behave as object type with properties from all branches Intersection of object types should be a valid lower bound of the object type with properties from all branches Jan 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants