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

fix(eslint-plugin): [unified-signatures] exemptthis from optional parameter overload check#11005

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

Merged

Conversation

jedwards1211
Copy link
Contributor

@jedwards1211jedwards1211 commentedMar 28, 2025
edited
Loading

PR Checklist

Overview

InsignaturesDifferByOptionalOrRestParameter, checks the first parameter of both signatures. If one is athis parameter but not the other, thenreturn undefined instead ofkind: 'extra-parameter', so that no error is flagged.

@typescript-eslint
Copy link
Contributor

Thanks for the PR,@jedwards1211!

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 commentedMar 28, 2025
edited
Loading

Deploy Preview fortypescript-eslint ready!

NameLink
🔨 Latest commit44d6ac8
🔍 Latest deploy loghttps://app.netlify.com/sites/typescript-eslint/deploys/6814e3d4a5eac30008a25d0d
😎 Deploy Previewhttps://deploy-preview-11005--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: 98 (no change 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 commentedMar 28, 2025
edited
Loading

View yourCI Pipeline Execution ↗ for commit44d6ac8.

CommandStatusDurationResult
nx typecheck ast-spec✅ Succeeded<1sView ↗
nx run-many --target=build --exclude website --...✅ Succeeded5sView ↗
nx run-many --target=clean✅ Succeeded10sView ↗

☁️Nx Cloud last updated this comment at2025-05-02 15:40:06 UTC

@jedwards1211jedwards1211force-pushed thefix-10982 branch 2 times, most recently fromea91923 to2532ff3CompareMarch 28, 2025 17:18
@jedwards1211jedwards1211 changed the titlefix(unified-signatures): exemptthis from optional parameter overload checkfix(eslint-plugin): exemptthis from optional parameter overload check in unified-signaturesMar 28, 2025
@codecovCodecov
Copy link

codecovbot commentedMar 28, 2025
edited
Loading

Codecov Report

Attention: Patch coverage is92.00000% with2 lines in your changes missing coverage. Please review.

Project coverage is 90.83%. Comparing base(cc2d6ec) to head(44d6ac8).
Report is 1 commits behind head on main.

Files with missing linesPatch %Lines
...ages/eslint-plugin/src/rules/unified-signatures.ts92.00%2 Missing⚠️
Additional details and impacted files
@@           Coverage Diff           @@##             main   #11005   +/-   ##=======================================  Coverage   90.83%   90.83%           =======================================  Files         497      497             Lines       50279    50304   +25       Branches     8297     8309   +12     =======================================+ Hits        45672    45696   +24- Misses       4592     4593    +1  Partials       15       15
FlagCoverage Δ
unittest90.83% <92.00%> (+<0.01%)⬆️

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

Files with missing linesCoverage Δ
...ages/eslint-plugin/src/rules/unified-signatures.ts94.26% <92.00%> (+0.08%)⬆️
🚀 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.

@jedwards1211jedwards1211 changed the titlefix(eslint-plugin): exemptthis from optional parameter overload check in unified-signatures[unified-signatures] fix(eslint-plugin): exemptthis from optional parameter overload check in unified-signaturesMar 28, 2025
@jedwards1211jedwards1211 changed the title[unified-signatures] fix(eslint-plugin): exemptthis from optional parameter overload check in unified-signaturesfix(eslint-plugin): [unified-signatures] exemptthis from optional parameter overload checkMar 28, 2025
JoshuaKGoldberg
JoshuaKGoldberg previously approved these changesMar 31, 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.

💯 Great first PR, 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 labelMar 31, 2025
@@ -310,6 +314,12 @@ export default createRule<Options, MessageIds>({
const shorter = sig1.length < sig2.length ? sig1 : sig2;
const shorterSig = sig1.length < sig2.length ? a : b;

// If one signature has explicit this type and another doesn't, they can't
// be unified.
if (isThisParam(sig1[0]) !== isThisParam(sig2[0])) {

Choose a reason for hiding this comment

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

Question -

Suggested change
if(isThisParam(sig1[0])!==isThisParam(sig2[0])){
if(isThisParam(sig1[0])||isThisParam(sig2[0])){

I was kind of thinking we would also want to exempt cases where they both includethis, sincethis: Foo | void isn't equivalent to the overload form (playground). Is that not the case?

Copy link
ContributorAuthor

@jedwards1211jedwards1211Mar 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

Wouldn't that break cases that should be flagged for merge like this?

functionfoo(this:SomeClass)functionfoo(this:SomeClass,x:number)

kirkwaiblinger reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hmm but using different logic, we could also exempt cases where some but not all signatures havethis: void without breaking the above example

kirkwaiblinger reacted with thumbs up emoji
Copy link
ContributorAuthor

@jedwards1211jedwards1211Mar 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

@kirkwaiblinger btw doesreturnsVoid (especially calling it with a function argument) do something tricky in your example that I'm not aware of? It seems to me instead of

overloadedThisVoid.call(returnsVoid(()=>'lol'));

you could just do

overloadedThisVoid.call((()=>{})())

Or more explicitly

overloadedThisVoid.call(1asanyasvoid)

Both of which trigger the same TypeScript error.

Choose a reason for hiding this comment

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

Hmm, yeah, I guess it would come down to special-casing aroundvoid, since, in addition to your example, which I agree with, we'd also want to consider:

functionfoo(this:Foo,x:number)functionfoo(this:Bar,x:number)

can still be

functionfoo(this:Foo|Bar,x:number)

Wonder if special-casing aroundvoid is even relevant for non-this parameters too?

functionfoo(x:void);functionfoo(x:number);

Would have to play around to figure that one out.

Copy link
ContributorAuthor

@jedwards1211jedwards1211Mar 31, 2025
edited by kirkwaiblinger
Loading

Choose a reason for hiding this comment

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

It appears that TS picks thethis type from the last overload when it comes to.call, lol.

functionfoo(this:string):void;functionfoo(this:number):void;functionfoo(){}foo.call(1)foo.call('a')// Argument of type 'string' is not assignable to parameter of type 'number'.(2345)functionbar(this:number):void;functionbar(this:string|boolean):void;functionbar(){}bar.call(1)// Argument of type 'number' is not assignable to parameter of type 'string | boolean'.(2345)bar.call('a')bar.call(true)

Copy link
ContributorAuthor

@jedwards1211jedwards1211Mar 31, 2025
edited
Loading

Choose a reason for hiding this comment

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

ah right, the unsoundness of TS function typing rears its head again
Do you know why TS doesn't treat embedded void expressions as an error the wayno-confusing-void-expression does? Would be curious to know the explicit rationale from the TS team.

Choose a reason for hiding this comment

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

It appears that TS picks thethis type from the last overload when it comes to.call, lol.

Huh. 👀 . Well - that the.bind()/.call()/.apply() types are going over my head at this point 😆

Choose a reason for hiding this comment

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

possibly related -microsoft/TypeScript#14107,microsoft/TypeScript#33815,microsoft/TypeScript#38353... they seem to have more to do with teh parameter types than thethis type, but anyway. Let's not stress too much about bind/call/apply type behavior, I suppose. 🤷

Choose a reason for hiding this comment

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

Do you know why TS doesn't treat embedded void expressions as an error the wayno-confusing-void-expression does? Would be curious to know the explicit rationale from the TS team.

Not off the top of my head, but I'm sure you'll get (or more likely be pointed to) a thorough answer if you ask in the TS discord.

@JoshuaKGoldbergJoshuaKGoldberg removed the 1 approval>=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labelApr 14, 2025
kirkwaiblinger
kirkwaiblinger previously approved these changesApr 28, 2025
@kirkwaiblingerkirkwaiblingerenabled auto-merge (squash)April 28, 2025 04:55
param: TSESTree.Parameter | undefined,
): param is TSESTree.Identifier {
return param?.type === AST_NODE_TYPES.Identifier && param.name === 'this';
function isThisParam(param: TSESTree.Parameter | undefined): boolean {

Choose a reason for hiding this comment

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

FYI/PSA - I changed this not to be a type predicate since it's only valid in thetrue branch, not thefalse branch (the function returningfalse does not imply thatparam isnot aTSESTree.Identifier).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Oh I didn't think about TS doing a negative refinement when the function returnsfalse. It would be useful to be able to declare an assertion that only refines in thetrue case

kirkwaiblinger reacted with thumbs up emoji
@kirkwaiblingerkirkwaiblingerenabled auto-merge (squash)May 2, 2025 15:25
@kirkwaiblingerkirkwaiblinger merged commit5453629 intotypescript-eslint:mainMay 2, 2025
55 checks passed
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsMay 10, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@kirkwaiblingerkirkwaiblingerkirkwaiblinger approved these changes

@JoshuaKGoldbergJoshuaKGoldbergJoshuaKGoldberg left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Bug: [unified-signatures] thinks overloads with and without this type annotation can be merged
3 participants
@jedwards1211@JoshuaKGoldberg@kirkwaiblinger

[8]ページ先頭

©2009-2025 Movatter.jp