eslint-plugin-flowtype icon indicating copy to clipboard operation
eslint-plugin-flowtype copied to clipboard

Flow generics trigger no-shadow rule

Open rjdestigter opened this issue 7 years ago • 4 comments

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",

rjdestigter avatar Sep 25 '17 14:09 rjdestigter

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 https://github.com/babel/babel-eslint/issues/223

zeorin avatar Jun 01 '18 08:06 zeorin

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;

zeorin avatar Jun 01 '18 09:06 zeorin

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

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

the StateShape gets treated as type declaration, not usage

kubijo avatar Dec 11 '18 13:12 kubijo

same issue here


type TProps = {
 someKey: Object
}

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

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

}

someKey is declared in upperscope

hayk94 avatar Dec 18 '18 13:12 hayk94