Skip to content

[no-explicit-any] allow any in a keyof any expression #3206

Closed
@iliazeus

Description

@iliazeus
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/no-explicit-any": 2
  }
}
function getNumber<K extends keyof any, T extends { [P in K]: number }>(key: K, obj: T): number {
  return obj[key];
}

Currently, the expression keyof any is probably the only (sane) way of saying "a type of things that can be object keys". But it is disallowed under no-explicit-any.

The long way of string | number | symbol isn't portable enough because of the symbol part.

Versions

package version
@typescript-eslint/eslint-plugin 4.18.0
@typescript-eslint/parser 4.18.0
TypeScript 4.2.3
ESLint 7.22.0
node 14.15.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: 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