Closed
Description
Repro
no-unnecessary-type-assertion
is resolving key
keys on React components inconsistently with normal function call. Please take a look at the code for better descrition.
{
"rules": {
"@typescript-eslint/no-unnecessary-type-assertion": "error"
}
}
const appTest = () => {
type ArtificialKey = string | number;
interface ReactAttributeArtificial {
key?: ArtificialKey;
}
type Data = {
id?: null | string | number;
};
const Test = (props: Data) => {
// ✅no tsc errors
// ✅no eslint errors
return ChildFn({ key: props.id! });
};
const Test2 = (props: Data) => {
// 🚨ESLINT error.
// 🚨If you remove non null operator it will be an compile error
return <ChildCmp key={props.id!} />;
};
const ChildFn = (props: ReactAttributeArtificial) => 'Hello';
const ChildCmp = () => <div>Hello</div>;
};
Expected Result
It should behave consistently
Actual Result
JSX key
is resolved in not correct way ?
Additional Info
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.2.0 |
@typescript-eslint/parser |
2.2.0 |
TypeScript |
3.6.3 |
ESLint |
6.3.0 |
node |
10 |
yarn |
1.17 |