eslint-plugin-flowtype
eslint-plugin-flowtype copied to clipboard
Flow generics trigger no-shadow rule
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",
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
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;
This sure seems like a bug in the parsing phase ...
const x = {
getDefaults<StateShape>(...args) { /* ... */ }
}
the StateShape
gets treated as type declaration, not usage
same issue here
type TProps = {
someKey: Object
}
class MainWrapper extends React.Component<TProps, TState> {
render() {
const { someKey } = this.props
}
}
someKey is declared in upperscope