8000 [no-explicit-any] Allow safe usages of `any` · Issue #1071 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
[no-explicit-any] Allow safe usages of any #1071
Closed
@OliverJAsh

Description

@OliverJAsh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0