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 for v0.42 Object type spread #207

Closed
torarnek opened this issue Mar 20, 2017 · 5 comments
Closed

Support for v0.42 Object type spread #207

torarnek opened this issue Mar 20, 2017 · 5 comments

Comments

@torarnek
Copy link

Version v0.42 of flow comes with support for object type spread (type TypeB = { ...TypeA };)

I currently get "Parsing error: Unexpected token"

It would have been great with support for this.

@danharper
Copy link
Collaborator

There's an issue open in Babylon (the parser) for this, should be out soon babel/babylon#418.

@istarkov
Copy link

The issue is merged but I still get Unexpected token

@danharper
Copy link
Collaborator

It's been merged into Babylon v7, which isn't released yet.

babel/babylon#418 (comment)

@voldern
Copy link

voldern commented Jun 9, 2017

It seems like it should be possible to support this in the plugin. When I tried to look into this it seems like it could be supported by updating to babel-eslint v7.2.3 and to check if the type of the identifierNode is ObjectTypeSpreadProperty and skipping that node.

This is assuming that we don't want to include spread identifiers in the duplicate key check. Would that makes sense since it's not a key?

If we want to include spread identifiers in the duplicate check we would have to decide if we should allow the same identifier just with different refinements. Then its should just be a matter of handling it in https://github.com/gajus/eslint-plugin-flowtype/blob/master/src/utilities/getParameterName.js.

One problem is that updating to babel-eslint v7.2.3 seems to break several of the no-unused-vars rules:

no-unused-vars must trigger an error in these cases
...
3) import type A from "a"; (function<T: A>(): T {})
4) (function<T: A>(): T {}); import type A from "a"
5) import type {A} from "a"; (function<T: A>(): T {})
6) (function<T: A>(): T {}); import type {A} from "a"
7) (function<T: A>(): T {}); import type {a as A} from "a"
8) type A = {}; function x<Y: A>(i: Y) { i }; x()
9) function x<Y: A>(i: Y) { i }; type A = {}; x()
10) type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()
11) function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()

Haven't had time yet to investigate why this happens.

@kmiyashiro
Copy link

kmiyashiro commented Jun 15, 2017

The babylon fix was backported to 6, so this should be possible to fix in eslint-plugin-flowtype. Upgrading babel-eslint to 7.2.3 and running on a simple check causes an error.

I'm using babel-core@6.25 and babel-eslint@7.2.3.

type Props = {
  foo: string
}

type OtherProps = {
  ...Props
}

output of eslint

Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined
    at /Users/kelly/src/product-store/node_modules/eslint-plugin-flowtype/dist/rules/noDupeKeys.js:76:31
    at arrayEach (/Users/kelly/src/product-store/node_modules/lodash/lodash.js:537:11)
    at Function.forEach (/Users/kelly/src/product-store/node_modules/lodash/lodash.js:9359:14)
    at EventEmitter.checkForDuplicates (/Users/kelly/src/product-store/node_modules/eslint-plugin-flowtype/dist/rules/noDupeKeys.js:71:22)
    at emitOne (events.js:96:13)
    at EventEmitter.emit (events.js:188:7)
    at NodeEventGenerator.applySelector (/Users/kelly/src/product-store/node_modules/eslint/lib/util/node-event-generator.js:265:26)
    at NodeEventGenerator.applySelectors (/Users/kelly/src/product-store/node_modules/eslint/lib/util/node-event-generator.js:294:22)
    at NodeEventGenerator.enterNode (/Users/kelly/src/product-store/node_modules/eslint/lib/util/node-event-generator.js:308:14)
    at CodePathAnalyzer.enterNode (/Users/kelly/src/product-store/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:602:23)
    at CommentEventGenerator.enterNode (/Users/kelly/src/product-store/node_modules/eslint/lib/util/comment-event-generator.js:98:23)

I tried opening this in chrome dev tools and I see that there is indeed no value

screen shot 2017-06-14 at 5 04 28 pm

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

6 participants