-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(eslint-plugin): [no-unnecessary-type-parameters] descend into all parts of mapped types in no-unnecessary-type-parameters #9530
Conversation
Thanks for the PR, @danvk! 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 on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 9af9db6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9530 +/- ##
=======================================
Coverage 88.37% 88.37%
=======================================
Files 419 419
Lines 14618 14621 +3
Branches 4279 4280 +1
=======================================
+ Hits 12919 12922 +3
Misses 1375 1375
Partials 324 324
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Incidentally @JoshuaKGoldberg I'm not sure why the new test case doesn't trigger the "quick path:" typescript-eslint/packages/eslint-plugin/src/rules/no-unnecessary-type-parameters.ts Lines 59 to 63 in bebbd0c
declare function mapObj<
K extends string,
V, // Type parameter V is used only once
>(
obj: { [key in K]: V },
fn: (key: K, val: V) => number,
): number[]; I would have expected it to contain the references. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fast follow! ⚡
Just requesting changes on a bit of testing. This basically an approval otherwise.
packages/eslint-plugin/tests/rules/no-unnecessary-type-parameters.test.ts
Outdated
Show resolved
Hide resolved
This should be good to go. I have no idea what the "Semantic Breaking Change PR / Validate Breaking Change PR (pull_request_target)" is about, and the error logs aren't illuminating:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful, thanks! 🙌
PR Checklist
Overview
Mapped types have three parts: the type parameter, the template type and the constraint type:
The rule previously descended into the typeParameter. It doesn't need to descend into the constraintType because we get that through another code path. It does need to descend into the templateType, though.
One wrinkle is that if the mapped type is something like
{[k in 'a']: T}
, then TypeScript will treat it like{a: T}
and we'll process it as an object type. In this case, we need to avoid also processing it as a mapped type, even thoughisMappedType
returns true.