Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Objects do not intersect properly #1172

Closed
pasha-mf opened this issue Dec 10, 2015 · 2 comments
Closed

Objects do not intersect properly #1172

pasha-mf opened this issue Dec 10, 2015 · 2 comments

Comments

@pasha-mf
Copy link
Contributor

It is my understanding that an intersection (&) of two objects is equivalent to merging type declarations of those objects. So in the example below types A and B should be identical. As the test demonstrates, they are not.

/* @flow */

type A = {x: number} & {y: number};
type B = {x: number, y: number};
function test (a: A, b: B) {
  (a: B); // Flow error
  (b: A); // ok
}
@sterpe
Copy link

sterpe commented Jan 21, 2016

My problem was something more like this

/* @flow */

/* ::
  type Quux = ({foo: string, baz: string} & Array<any>)
*/

const assign /* : Function */ = require('object-assign')

function Q() /* : Quux */ {
  const quux = assign([], {foo: 'bar'})
  return quux
}

Q().foo
Q().baz
Q().push(1)
Q().push('a')
Q().quux // Error !

module.exports = Q

@samwgoldman
Copy link
Member

Thanks, @pasha-mf. Merging this into the issue I created. @sterpe, creating a separate issue for object/array intersection types. Going to track everything intersection related in a new meta-issue.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants