Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(eslint-plugin): [no-explicit-any] suggest to replace keyof any with PropertyKey#11032

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

dbarabashh
Copy link
Contributor

PR Checklist

Overview

Enhanced theno-explicit-any rule to suggest replacingkeyof any with PropertyKey. added detection, helpful suggestion messages, auto-fix support, and test coverage.

KuSh reacted with hooray emoji
@typescript-eslint
Copy link
Contributor

Thanks for the PR,@dbarabashh!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint.

@netlifyNetlify
Copy link

netlifybot commentedApr 5, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit2c6c6fa
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/67f679f05f98ab00098a66bf
😎 Deploy Previewhttps://deploy-preview-11032--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 91 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to yourNetlify site configuration.

@nx-cloudNx Cloud
Copy link

nx-cloudbot commentedApr 5, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commit2c6c6fa.

CommandStatusDurationResult
nx run-many --target=build --exclude website --...✅ Succeeded4sView ↗
nx run-many --target=clean✅ Succeeded10sView ↗

☁️Nx Cloud last updated this comment at2025-04-11 17:32:53 UTC

@dbarabashhdbarabashh changed the titlefeat(no-explicit-any): suggest to replace keyof any with PropertyKeyfeat(eslint-plugin): suggest to replace keyof any with PropertyKeyApr 5, 2025
@codecovCodecov
Copy link

codecovbot commentedApr 5, 2025
edited
Loading

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.01%. Comparing base(052b7f9) to head(2c6c6fa).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@##             main   #11032      +/-   ##==========================================- Coverage   88.03%   88.01%   -0.02%==========================================  Files         470      470                Lines       16801    16811      +10       Branches     4745     4749       +4     ==========================================+ Hits        14790    14797       +7- Misses       1664     1667       +3  Partials      347      347
FlagCoverage Δ
unittest88.01% <100.00%> (-0.02%)⬇️

Flags with carried forward coverage won't be shown.Click here to find out more.

Files with missing linesCoverage Δ
...ackages/eslint-plugin/src/rules/no-explicit-any.ts97.05% <100.00%> (+0.63%)⬆️

... and3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dbarabashh
Copy link
ContributorAuthor

dbarabashh commentedApr 5, 2025
edited
Loading

Hey,

I ran into a small issue. codecov is flagging line of code that is not covered by tests:

functioncreatePropertyKeyFixer(node:TSESTree.Node){return(fixer:TSESLint.RuleFixer)=>{if(node.parent&&node.parent.type===AST_NODE_TYPES.TSTypeOperator){returnfixer.replaceText(node.parent,'PropertyKey');}returnfixer.replaceText(node,'unknown');// ← This line isn't covered};}

It is fallback that should never actually run I only call this function when we've already checked that the node has a parent that іs a keyof operator.

what is the best way to handle this?

  • Just add ignore comment to make Codecov happy?not sure 😐
  • Delete fallback?
  • Try to somehow test this edge case (though that seems tricky)

Any thoughts on what is usually preferred for these kinds of situations? Thanks!

@JoshuaKGoldberg
Copy link
Member

Great question! We've been hoping to write a blog post on the subject:#10388.

Roughly, it's either of the following:

  • The code truly can never be hit, so it should be removed
  • The code can actually be hit, so test coverage should be added

If the type checker is pressuring you to write code that you don't think is necessary (e.g. thenode.parent checks) then you can either:

dbarabashh reacted with heart emoji

@JoshuaKGoldbergJoshuaKGoldberg added the awaiting responseIssues waiting for a reply from the OP or another party labelApr 7, 2025
@dbarabashh
Copy link
ContributorAuthor

Thanks for the detailed reply@JoshuaKGoldberg

I’ll go through all the topics you mentioned in your comment.

JoshuaKGoldberg reacted with heart emoji

@dbarabashh
Copy link
ContributorAuthor

dbarabashh commentedApr 7, 2025
edited
Loading

Thanks again for the comment you left it had a lot of great insights, and I especially enjoyed your article.

So, I pushed a commit with my solution.

Of course, its not the best one out there, but following your article, I intentionally picked the worst and most unsafe approach 🙃. That said, the situation isn't as simple as it seems, so I will try to explain it in words maybe someone will find it helpful in the future.

Using type assertion just to bypass type checking is generally a bad idea. Without solid test coverage, this approach can go wrong fast, and other node types might end up being handled incorrectly.

in this particular case, I came to the following conclusions:

  • Since we have a check insideisNodeWithinKeyofAny that guaranteesnode.parent exists and is of typeTSTypeOperator withoperator === 'keyof',
  • andcreatePropertyKeyFixer is only called after that check,
  • the previous version of createPropertyKeyFixer had an extra check for something that was already verified.

according to@JoshuaKGoldberg article, in this case, type assertion actuallyis the best strategy, because:

  • the check is indeed redundant (yikes),
  • and we know for sure that the type is correct (so we are not really bypassing the type system).
JoshuaKGoldberg reacted with laugh emoji

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for keeping working on this - I think you're in the right track with the removing a runtime check. 👍

@github-actionsgithub-actionsbot removed the awaiting responseIssues waiting for a reply from the OP or another party labelApr 9, 2025
@JoshuaKGoldbergJoshuaKGoldberg changed the titlefeat(eslint-plugin): suggest to replace keyof any with PropertyKeyfeat(eslint-plugin): [no-explicit-any] suggest to replace keyof any with PropertyKeyApr 9, 2025
Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Progress 🚀, but some un-resolved conversations still?

Copy link
Member

@JoshuaKGoldbergJoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

💯 thanks!

@JoshuaKGoldbergJoshuaKGoldberg added the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelApr 11, 2025
@JoshuaKGoldbergJoshuaKGoldberg merged commit3ccd79c intotypescript-eslint:mainApr 14, 2025
59 checks passed
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestApr 17, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.29.0 | 8.30.1 || npm        | @typescript-eslint/parser        | 8.29.0 | 8.30.1 |## [v8.30.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8301-2025-04-14)##### 🩹 Fixes-   **eslint-plugin:** fix mistake with eslintrc config generation ([#11072](typescript-eslint/typescript-eslint#11072))##### ❤️ Thank You-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.30.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8300-2025-04-14)##### 🚀 Features-   **eslint-plugin:** \[no-explicit-any] suggest to replace keyof any with PropertyKey ([#11032](typescript-eslint/typescript-eslint#11032))##### 🩹 Fixes-   **eslint-plugin:** \[promise-function-async] use a different error message for functions with promise and non-promise types ([#10950](typescript-eslint/typescript-eslint#10950))##### ❤️ Thank You-   Dima Barabash [@dbarabashh](https://github.com/dbarabashh)-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.29.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8291-2025-04-07)##### 🩹 Fixes-   **eslint-plugin:** \[no-deprecated] report on deprecated imported variable used as property ([#10998](typescript-eslint/typescript-eslint#10998))##### ❤️ Thank You-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestApr 17, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.29.0 | 8.30.1 || npm        | @typescript-eslint/parser        | 8.29.0 | 8.30.1 |## [v8.30.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8301-2025-04-14)##### 🩹 Fixes-   **eslint-plugin:** fix mistake with eslintrc config generation ([#11072](typescript-eslint/typescript-eslint#11072))##### ❤️ Thank You-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.30.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8300-2025-04-14)##### 🚀 Features-   **eslint-plugin:** \[no-explicit-any] suggest to replace keyof any with PropertyKey ([#11032](typescript-eslint/typescript-eslint#11032))##### 🩹 Fixes-   **eslint-plugin:** \[promise-function-async] use a different error message for functions with promise and non-promise types ([#10950](typescript-eslint/typescript-eslint#10950))##### ❤️ Thank You-   Dima Barabash [@dbarabashh](https://github.com/dbarabashh)-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.29.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8291-2025-04-07)##### 🩹 Fixes-   **eslint-plugin:** \[no-deprecated] report on deprecated imported variable used as property ([#10998](typescript-eslint/typescript-eslint#10998))##### ❤️ Thank You-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestApr 19, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.29.0 | 8.30.1 || npm        | @typescript-eslint/parser        | 8.29.0 | 8.30.1 |## [v8.30.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8301-2025-04-14)##### 🩹 Fixes-   **eslint-plugin:** fix mistake with eslintrc config generation ([#11072](typescript-eslint/typescript-eslint#11072))##### ❤️ Thank You-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.30.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8300-2025-04-14)##### 🚀 Features-   **eslint-plugin:** \[no-explicit-any] suggest to replace keyof any with PropertyKey ([#11032](typescript-eslint/typescript-eslint#11032))##### 🩹 Fixes-   **eslint-plugin:** \[promise-function-async] use a different error message for functions with promise and non-promise types ([#10950](typescript-eslint/typescript-eslint#10950))##### ❤️ Thank You-   Dima Barabash [@dbarabashh](https://github.com/dbarabashh)-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.29.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8291-2025-04-07)##### 🩹 Fixes-   **eslint-plugin:** \[no-deprecated] report on deprecated imported variable used as property ([#10998](typescript-eslint/typescript-eslint#10998))##### ❤️ Thank You-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovatebot added a commit to andrei-picus-tink/auto-renovate that referenced this pull requestApr 20, 2025
| datasource | package                          | from   | to     || ---------- | -------------------------------- | ------ | ------ || npm        | @typescript-eslint/eslint-plugin | 8.29.0 | 8.30.1 || npm        | @typescript-eslint/parser        | 8.29.0 | 8.30.1 |## [v8.30.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8301-2025-04-14)##### 🩹 Fixes-   **eslint-plugin:** fix mistake with eslintrc config generation ([#11072](typescript-eslint/typescript-eslint#11072))##### ❤️ Thank You-   Kirk Waiblinger [@kirkwaiblinger](https://github.com/kirkwaiblinger)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.30.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8300-2025-04-14)##### 🚀 Features-   **eslint-plugin:** \[no-explicit-any] suggest to replace keyof any with PropertyKey ([#11032](typescript-eslint/typescript-eslint#11032))##### 🩹 Fixes-   **eslint-plugin:** \[promise-function-async] use a different error message for functions with promise and non-promise types ([#10950](typescript-eslint/typescript-eslint#10950))##### ❤️ Thank You-   Dima Barabash [@dbarabashh](https://github.com/dbarabashh)-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.## [v8.29.1](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8291-2025-04-07)##### 🩹 Fixes-   **eslint-plugin:** \[no-deprecated] report on deprecated imported variable used as property ([#10998](typescript-eslint/typescript-eslint#10998))##### ❤️ Thank You-   Ronen AmielYou can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsApr 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg approved these changes

Assignees
No one assigned
Labels
1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Enhancement: [no-explicit-any] suggest to replace keyof any with PropertyKey
2 participants
@dbarabashh@JoshuaKGoldberg

[8]ページ先頭

©2009-2025 Movatter.jp