Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: [no-explicit-any] suggest to replace keyof any with PropertyKey #11009

Open
4 tasks done
KuSh opened this issue Mar 29, 2025 · 1 comment · May be fixed by #11032
Open
4 tasks done

Enhancement: [no-explicit-any] suggest to replace keyof any with PropertyKey #11009

KuSh opened this issue Mar 29, 2025 · 1 comment · May be fixed by #11032
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@KuSh
Copy link
Contributor

KuSh commented Mar 29, 2025

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-explicit-any

Description

Suggest to replace keyof any (and keyof never?) with PropertyKey as it is more explicit.
This can even be an auto fixable thing.

Fail

const integer = <TKey extends keyof any, TTarget extends { [K in TKey]: number }>(
  target: TTarget,
  key: TKey
) => { /* ... */ };

Pass

const integer = <TKey extends PropertyKey, TTarget extends { [K in TKey]: number }>(
  target: TTarget,
  key: TKey
) => { /* ... */ };

Additional Info

Extracted from #3206

@KuSh KuSh added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Mar 29, 2025
@JoshuaKGoldberg
Copy link
Member

Interesting idea! My vote is 👍, this would be a nice improvement to the rule. Knowing that keyof any gives string | number | symbol / PropertyKey is a bit niche of knowledge. I'd wager that some non-trivial slice of users have copy & pasted it then gotten confused about the rule reporting.

@kirkwaiblinger kirkwaiblinger added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants