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

Support type spread in flow-types #2140

Closed
StokeMasterJack opened this issue May 13, 2017 · 7 comments
Closed

Support type spread in flow-types #2140

StokeMasterJack opened this issue May 13, 2017 · 7 comments

Comments

@StokeMasterJack
Copy link

Flow supports the below syntax but babel (or one of the tools used by create-react-app) fails to compile the file. Giving this error:

Module build failed: TypeError: Cannot read property 'typeAnnotation' of undefined

type Data = {
  firstName: string,
  lastName: string,
};

type State = {
  ...Data,
  isNew: boolean
};
@gaearon
Copy link
Contributor

gaearon commented May 13, 2017

Need someone to help investigate why. Maybe we need to update Babel version or something.

@Timer
Copy link
Contributor

Timer commented May 13, 2017

We should probably upgrade all development tooling packages before the 0.10 release.

@gaearon
Copy link
Contributor

gaearon commented May 13, 2017

Yea.

@kmiyashiro
Copy link

Has anyone tracked this down? I've tried upgrading all dependencies related to babel, flow and eslint, but I'm still getting this error when I use spread in type objects.

@kmiyashiro
Copy link

I don't know what's going on babel/babel-eslint#443

@chiptus
Copy link

chiptus commented Nov 24, 2017

For now we can use intersection types:

type State = Data & {
  isNew: boolean
};

although if Data has isNew prop that is not boolean it will end with an intersection type that might be invalid, for example:

type Data = {
  isNew: string
}

then State will end up:

type State = {
  isNew: string & boolean
}

@Timer Timer added this to the 2.0.0 milestone Nov 24, 2017
@gaearon
Copy link
Contributor

gaearon commented Jan 20, 2018

I verified this no longer reproduces in 2.x alphas. You can try them: #3815.

@gaearon gaearon closed this as completed Jan 20, 2018
@lock lock bot locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants