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

Flow type spread appears unsupported as of 6.25.0 #488

Closed
rsolomon opened this issue Jun 14, 2017 · 10 comments
Closed

Flow type spread appears unsupported as of 6.25.0 #488

rsolomon opened this issue Jun 14, 2017 · 10 comments

Comments

@rsolomon
Copy link

rsolomon commented Jun 14, 2017

Given the following code:

export type Test1 = {
  a: number,
};

export type Test2 = {
  ...Test1,
  b: string,
};

And running eslint@3.19.0 with babel-core@6.25.0 yields the following error:

Cannot read property '1' of undefined
TypeError: Cannot read property '1' of undefined
    at scope.references.forEach.reference (node_modules/eslint/lib/rules/no-use-before-define.js:206:83)

Note that disabling the no-use-before-define rule does fix the problem, but it suggests that there's still something underlying that is unsupported.

@rsolomon rsolomon changed the title Still cannot use Flow type spread with 6.25.0 Flow type spread appears unsupported as of 6.25.0 Jun 14, 2017
@rosskevin
Copy link

This might be due to earlier dependencies in your transitive dependency tree. What is your output of yarn list babel-core babel-types?

If you can't get your dependencies updated, you can force up these with yarn --flat.

@soda0289
Copy link
Contributor

Sounds like a duplicate of this: #485
I'm working on a solution should be posted soon.

@rsolomon
Copy link
Author

Aye I did see that one, but the error being reported is different. I wasn't 100% sure if it was the same root cause. Happy to close this one if so.

@soda0289
Copy link
Contributor

The problem is with the scope analysis tool. We currently monkey patch it to handle type definitions but it needs to be updated to handle spread.

@kmiyashiro
Copy link

kmiyashiro commented Jun 15, 2017

Edit: Sorry, this is probably a bug in eslint-plugin-flowtype. (gajus/eslint-plugin-flowtype#207)

I also get an error, although it's a different one. I'm using babel-core@6.25 and babel-eslint@7.2.3. Is this just an error in eslint-plugin-flowtype?

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

@hzoo
Copy link
Member

hzoo commented Jun 15, 2017

Just FYI babel-core is unrelated to eslint/babel-eslint. The only thing babel-eslint uses is the parser (babylon) and some utils like babel-types.

And yes it probably doesn't handle it given the rule that is erroring is no-undef/no-use-before-define

@irnc
Copy link

irnc commented Jul 21, 2017

The issue seems to be because of missing range property on GenericTypeAnnotation and Identifier nodes stored under argument of ObjectTypeSpreadProperty.

Issue could be reproduced in ASP Explorer using babel-eslint-7.2.3, i.e. there is no range, while start and end are in place.

Using babylon7-7.0.0-beta.12 with ranges option gives the range property on all nodes.

babel-eslint@7.2.2 uses babylon@^6.16.1, so issue should be fixed somewhere between 6.16.1 and 7.0.0-beta.12.

@hzoo
Copy link
Member

hzoo commented Nov 6, 2017

Clsoing for inactivity, I believe updating the package version should work

@hzoo hzoo closed this as completed Nov 6, 2017
@niieani
Copy link

niieani commented Nov 8, 2017

@hzoo I'm using the latest version of babel-eslint (8.0.2) and still get the same error from eslint.

@sibelius
Copy link

sibelius commented May 9, 2018

"eslint": "^4.19.1",
"babel-eslint": "^8.2.3",

fixed the issue for me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants