Skip to content

fix(eslint-plugin): [no-unnecessary-type-parameters] check mapped alias type arguments #9741

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

Conversation

JoshuaKGoldberg
Copy link
Member

PR Checklist

Overview

I'm not 100% on my understanding here. But what I think is happening is that TypeScript is inlining the resolved parts of the conditional type when possible. type.aliasTypeArguments is the piece that still has a reference to the type arguments <T, S>.

💖

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @JoshuaKGoldberg!

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.

Copy link

netlify bot commented Aug 6, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit cc6563c
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66c37309577a000008df9138
😎 Deploy Preview https://deploy-preview-9741--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: 99 (🔴 down 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (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 your Netlify site configuration.

Copy link

nx-cloud bot commented Aug 6, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit cc6563c. 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 2 targets

Sent with 💌 from NxCloud.

@JoshuaKGoldberg JoshuaKGoldberg requested a review from a team August 6, 2024 19:51
Copy link

codecov bot commented Aug 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.02%. Comparing base (3d78392) to head (cc6563c).
Report is 40 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9741      +/-   ##
==========================================
+ Coverage   87.93%   88.02%   +0.09%     
==========================================
  Files         403      406       +3     
  Lines       13796    13869      +73     
  Branches     4022     4052      +30     
==========================================
+ Hits        12131    12208      +77     
+ Misses       1358     1352       -6     
- Partials      307      309       +2     
Flag Coverage Δ
unittest 88.02% <100.00%> (+0.09%) ⬆️

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

Files Coverage Δ
...plugin/src/rules/no-unnecessary-type-parameters.ts 94.89% <100.00%> (-0.08%) ⬇️

... and 24 files with indirect coverage changes

kirkwaiblinger
kirkwaiblinger previously approved these changes Aug 16, 2024
Copy link
Member

@kirkwaiblinger kirkwaiblinger left a comment

Choose a reason for hiding this comment

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

I think this makes sense. Yay for test cases 😅

@kirkwaiblinger kirkwaiblinger added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 16, 2024
@JoshuaKGoldberg JoshuaKGoldberg requested a review from danvk August 19, 2024 11:18
Copy link
Collaborator

@danvk danvk left a comment

Choose a reason for hiding this comment

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

I don't think this is the right way to handle this case.

I pulled this change down locally and set a breakpoint on line 292 to see which tests hit the new code path. This was the first one:

> type
"Extract<AccessorPropertyComputedName, { type: NodeType; }>"
> type.aliasSymbol.declarations[0].getText()
'type Extract<T, U> = T extends U ? T : never;'
> > type.aliasTypeArguments.map(t => type.checker.typeToString(t))
[ 'AccessorPropertyComputedName', '{ type: NodeType; }' ]
> checkType
AccessorPropertyComputedName
> extendsType
{ type: NodeType; }

It's pretty weird that TS "inlines" type aliases that are conditional types like this. But since the same types appear in both type.aliasTypeArguments as type.checkType and type.extendsType, this change means we'll start double-counting them.

#9721 shows that we need the recursive call via aliasTypeArguments. So in the case that a type is both a type alias instantiation and a conditional type, I think it's safer to only treat it as a type alias instantiation and ignore the extra information.

In practice, that just means moving the last "catch-all" higher up. This lets us remove some duplicated logic. Here's a commit that does that, all tests still pass:
danvk@bacd28d

@JoshuaKGoldberg
Copy link
Member Author

Oh awesome! @danvk do you have bandwidth to send a PR? I can add that better change to this PR if not.

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labels Aug 19, 2024
@danvk
Copy link
Collaborator

danvk commented Aug 19, 2024

Oh awesome! @danvk do you have bandwidth to send a PR? I can add that better change to this PR if not.

Sure, here's a PR to merge that commit into your PR branch JoshuaKGoldberg#323

@JoshuaKGoldberg JoshuaKGoldberg added 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge and removed awaiting response Issues waiting for a reply from the OP or another party labels Aug 19, 2024
@JoshuaKGoldberg JoshuaKGoldberg merged commit 94f7c99 into typescript-eslint:main Aug 20, 2024
60 of 63 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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
Development

Successfully merging this pull request may close these issues.

Bug: [no-unnecessary-type-parameters] False positive on curried functions
3 participants