Closed
Description
Repro
{
"rules": {
"@typescript-eslint/no-explicit-any": 2
}
}
type Component<P> = (props: P) => unknown;
type Props = { foo: string; }
declare const MyComponent: Component<Props>;
declare function withBar<T extends Component<any>>(
component: T,
): Component<Parameters<T>[0] & { bar: string }>;
const NewComponent = withBar(MyComponent);
Expected Result
No error
Actual Result
Error
Additional Info
You might think we should change any
to unknown
, to fix this error:
-declare function withBar<T extends Component<any>>(
+declare function withBar<T extends Component<unknown>>(
… however, if we do that, the function call withBar
will fail under strictFunctionTypes
:
/*
Argument of type 'Component<Props>' is not assignable to parameter of type 'Component<unknown>'.
Type 'unknown' is not assignable to type 'Props'.
*/
const NewComponent = withBar(MyComponent);
For this reason, I believe this is a valid and safe place to use any
.
The rule no-explicit-any
does exactly what it says on the tin—it prevents all explicit usages of any
. Perhaps what I am asking for is a separate rule—one that only disallows unsafe usages of any
—although I would question why you would want to disallow all explicit usages including safe ones.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
2.2.0 |
@typescript-eslint/parser |
2.2.0 |
TypeScript |
3.6.3 |
ESLint |
5.16.0 |
node |
12.8.1 |
npm |
6.10.2 |