Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Flowtype's new object spread gives parsing error #443

Closed
niieani opened this issue Mar 17, 2017 · 15 comments
Closed

Flowtype's new object spread gives parsing error #443

niieani opened this issue Mar 17, 2017 · 15 comments

Comments

@niieani
Copy link

niieani commented Mar 17, 2017

Flowtype's new feature, type object spread isn't getting parsed properly: facebook/flow@ad443dc

Example:

type A = {...TypeA, ...TypeB}
@danez
Copy link
Member

danez commented Mar 17, 2017

This is an issue in babylon which does not support this syntax yet.

@niieani
Copy link
Author

niieani commented Apr 6, 2017

@danez Babylon issue was fixed!

@niieani
Copy link
Author

niieani commented Apr 13, 2017

The Babylon issue was fixed, but only in babylon ^7. babel-eslint is currently dependent on ^6. Any news on migration to ^7?

The nasty workaround is to use the comment-style Flow type:

export type A = {a: string}
export type B = {b: number}
/* :: type _C = {...A, ...B} */
export type C = _C

@tomek-he-him
Copy link

tomek-he-him commented Apr 21, 2017

It’s a bit less ugly if you just comment out the spread type:

export type C = {
  /* :: ...A, */
  /* :: ...B, */
}

@AndreyKozlov1984
Copy link

AndreyKozlov1984 commented May 6, 2017

The other possible fix is this:
Make a fork of babel-eslint, like https://github.com/ZeusTheTrueGod/babel-eslint
change the package.json so the dependency on babylon is "7.0.0-beta.8" and then run "yarn install". Now your babel-eslint uses the latest babylon parser. If you run yarn test then you'll see 2 failures regarding the name of AST elements, but they are false positives. push your changes back to your fork of the repo.

Now, in your main project, get rid of existing babel-eslint via yarn remove babel-eslint, and then add the modified version via, for example, yarn add --dev ZeusTheTrueGod/babel-eslint.

After that ensure that 1) eslint still works on your project 2) you can use object spread syntax without any further problems!

export type A = {a: string}
export type B = {b: number}
type C = {...A, ...B} 

@mjomble
Copy link

mjomble commented May 6, 2017

...change the package.json so the dependency on babylon is "7.0.0-beta.8"...

Actually, this should no longer be required as the change has also been backported to babylon 6.x: babel/babylon#476

Furthermore, a specific fix for this has been applied to babel-eslint: #465

So all we need is a new babel-eslint release, for which even the version number update has already been made: 94bb5a1

But the actual release has not yet been made. @zertosh @kittens @danez do you have more info?

@AndreyKozlov1984
Copy link

@mjomble , everything worked from yarn:

yarn remove --dev babel-eslint
yarn add --dev babel-eslint

That installed a 7.2.3 version, not sure why, because that tag is not present in a github repo.

@mjomble
Copy link

mjomble commented May 6, 2017

Ah, weird, I guess the new release was pushed to npm, but wasn't created on Github.

@AndreyKozlov1984
Copy link

@lgraziani2712 Same issue!
It seems like latest babel / babylon is not used in the webpack chain. I disabled those extra rules, but still nothing helped. I'm researching the issue at this moment

@lgraziani2712
Copy link

lgraziani2712 commented May 7, 2017

****, I removed the comment sorry!

I said that @ZeusTheTrueGod comment solved the babel-eslint issue but I get a new one.

BTW, that new one is related to eslint-plugin-react. Nothing to do here I think.

@AndreyKozlov1984
Copy link

It seems like we need a babel 7 in a webpack in order to get this working. Only babel 7 depends on a babylon 7!

@lgraziani2712
Copy link

lgraziani2712 commented May 7, 2017

Uhmm, I just disabled react/prop-types: 2 from my eslint config file, and stopped complaining, so I can confirm is an eslint-plugin-react issue, specifically with prop-types rule.

Edit: reported jsx-eslint/eslint-plugin-react#1178

@AndreyKozlov1984
Copy link

AndreyKozlov1984 commented May 7, 2017

Ok, so here is what I've found - if you don't have an up-to date babel-core at least 6.24.1 - then even that simple babel command on a file containing type X={...Y} will fail. May be that will help someone to fix an issue in the future

@rosskevin
Copy link

If anyone can spot the error in my attempt, please let me know, here is a repo:
https://github.com/rosskevin/babel-eslint-473-flow-spread

@rsolomon
Copy link

@rosskevin I'm experiencing the same issue, and opened a ticket for it here:

#488

I still believe that it is not fully supported in 6.25.0

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

9 participants