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

Flow does not infer type on spread #7048

Closed
pronebird opened this issue Oct 19, 2018 · 1 comment
Closed

Flow does not infer type on spread #7048

pronebird opened this issue Oct 19, 2018 · 1 comment

Comments

@pronebird
Copy link

Flow is a little dumb when it comes to spread.

// @flow

const data = {
  event: ((): string => { return 'archive' })(),
  createdAt: +Date.now(),
  id: 1,
};

(data: {
 event: string,
 createdAt: number,
 id: number,
});

({
  ...data,
  event: 'archive',
  createdAt: new Date(data.createdAt),
}: {
  event: 'archive',
  createdAt: Date,
 id: number,
})

Gives the following output:

15: ({
     ^ Cannot cast object literal to object type because number [1] is incompatible with `Date` [2] in property `createdAt`.
References:
11:  createdAt: number,
                ^ [1]
21:   createdAt: Date,
                 ^ [2]
15: ({
     ^ Cannot cast object literal to object type because string [1] is incompatible with string literal `archive` [2] in property `event`.
References:
10:  event: string,
            ^ [1]
20:   event: 'archive',
             ^ [2]

Wat? 🤔

@wchargin
Copy link
Contributor

Duplicate of #6108.

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

4 participants