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 generics trigger no-shadow rule #275

Open
rjdestigter opened this issue Sep 25, 2017 · 4 comments
Open

Flow generics trigger no-shadow rule #275

rjdestigter opened this issue Sep 25, 2017 · 4 comments
Labels

Comments

@rjdestigter
Copy link

Declarations like:

export function foo<T>(bar: T) {
  return bar
}

are marked by the linter as 'T' is already declared in the upper scope. (no-shadow)

Versions:

    "babel-eslint": "8.0.0",
    "eslint": "4.7.2",
    "eslint-config-airbnb": "15.1.0",
    "eslint-config-prettier": "2.6.0",
    "eslint-plugin-flowtype": "2.36.0",
    "eslint-plugin-import": "2.7.0",
    "eslint-plugin-jsx-a11y": "6.0.2",
    "eslint-plugin-prettier": "2.3.1",
    "eslint-plugin-react": "7.4.0",
    "flow-bin": "0.55.0",
@zeorin
Copy link

zeorin commented Jun 1, 2018

I have a similar error. For the following code

// @flow strict

import React, { type Element } from 'react';

/** Just a test component */
const YourComponent = (): Element<'div'> => (
	<div>
		<span>test</span>
	</div>
);

export default YourComponent;

I get the error:

3:22 warning 'Element' is already declared in the upper scope no-shadow

Which is possibly a regression of babel/babel-eslint#223

@zeorin
Copy link

zeorin commented Jun 1, 2018

If I import the type Element like this:

import type { Element } from 'react';

as described in Flow's docs, I get same lint error.

But if I use the namespace import I get no error:

// @flow strict

import * as React from 'react';

/** Just a test component */
const YourComponent = (): React.Element<'div'> => (
	<div>
		<span>test</span>
	</div>
);

export default YourComponent;

And if I use the utility "internal" type notation I also get no error:

// @flow strict

import React from 'react';

/** Just a test component */
const YourComponent = (): React$Element<'div'> => (
	<div>
		<span>test</span>
	</div>
);

export default YourComponent;

@kubijo
Copy link

kubijo commented Dec 11, 2018

This sure seems like a bug in the parsing phase ...

const x = {
    getDefaults<StateShape>(...args) { /* ... */ }
}

the StateShape gets treated as type declaration, not usage

@hayk94
Copy link

hayk94 commented Dec 18, 2018

same issue here


type TProps = {
 someKey: Object
}

class MainWrapper extends React.Component<TProps, TState> {

  render() {
    const { someKey } = this.props
  }

}

someKey is declared in upperscope

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

No branches or pull requests

5 participants