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

Intersections have order dependent behavior #1735

Open
marcusdarmstrong opened this issue May 2, 2016 · 2 comments
Open

Intersections have order dependent behavior #1735

marcusdarmstrong opened this issue May 2, 2016 · 2 comments

Comments

@marcusdarmstrong
Copy link

// @flow
type Foo = {
  foo: string,
};

type Bar = {
  bar: string,
} & Foo;

type Baz = Foo & {
  baz: string,
};

const bat = (foo: Foo) => foo.foo;

export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
export const valid = ({ baz, ...bar }: Baz) => baz && bat(bar);

yields

src/components/test.js:15
 15: export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
                                                             ^^^^^^^^ function call
 14: const bat = (foo: Foo) => foo.foo;
                       ^^^ property `foo`. Property not found in
 15: export const invalid = ({ bar, ...baz }: Bar) => bar && bat(baz);
                                                                 ^^^ object pattern spread property


Found 1 error

Apologies if the names are confusing, I was trying to reduce the problem to a minimal case. But the point is, Bar and Baz are, in practice, the same type, however, the intersection operator handles them very differently. I expect this is the root cause of issues such as #1511, #1118, #824, and #1462.

@avikchaudhuri
Copy link
Contributor

Spread has a bunch of problems right now, independent of union/intersection bugs.

@chris-lock
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants