-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [unified-signatures] thinks overloads with and without this type annotation can be merged #10982
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
Comments
Okay I discovered that unifying them with |
Actually...reopening because |
Why isn't it possible to unify them as |
TypeScript doesn't seem to like |
|
Great thanks, that's helpful. This is starting to look like a bug to me.
I think what's happening is that the rule isn't understanding the difference between the implicit IMO: bug, but I'm not confident - seeking more input from @typescript-eslint/triage-team? |
This does beg the question why TypeScript should give |
If I understand correctly, |
Relates to #10959 and the TS issues mentioned there, too. |
Well I know TS can catch certain errors when you try to consume a return value of type But I haven't managed to think of a scenario where |
I think, tentatively, that basically both this issue and #10984 are pedantically "working as intended" tbh. Not convinced of this, though, so perhaps there's a counterexample, or some way that the reports can be improved. |
Would preferring |
Yes... these things are all closely related though so it's a bit tricky to avoid discussing related things. Looking again, neither function overloaded(): void;
function overloaded(this: String): void;
function overloaded() { }
function unionWithUndefined(this: String | undefined): void { }
function unionWithVoid(this: String | void): void { }
function optionalThis(this?: String) { } // ERROR, comma expected
const o = { overloaded, unionWithUndefined, unionWithVoid }
overloaded();
o.overloaded();
overloaded.bind(returnsVoid(() => 'lol'))(); // ERROR
unionWithUndefined(); // ERROR
o.unionWithUndefined(); // ERROR
unionWithUndefined.bind(returnsVoid(() => 'lol')); // ERROR
unionWithVoid();
o.unionWithVoid(); // ERROR
unionWithVoid.bind(returnsVoid(() => 'lol'));
function returnsVoid(cb: () => void): void {
return cb();
}
export { }; Unfortunately, the overloaded form is technically unsafe to implement, since it doesn't error on On balance, I'm now thinking, yes, this is a bug and the |
I guess there might be an idea of a separate issue to have |
Wow, okay I'll work on a PR to close this can of worms. I guess y'all are right to question what's the point of using this pattern, considering TS doesn't even give the desired errors in a lot of cases. |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.7.2&fileType=.tsx&code=KYDwDg9gTgLgBDAnmYcAKUIFsCWBnYAdRxgAsAlYPCAGwDdgo8AeAFQD44BeOAbwCg4cAPTC4AOkn8Avv37CAVAsEK4AVQJQaAQwB2AEzg4sYGsCzBdMbTBwRdcCADM4AbQzZ8wcQHcSFKloGJgBdXgABGhxdAGs4UhgYMDwALlF9YAYaCBQocSwIAC8cGh1xaABzYUsAWjUAZWF9CABjPGFCYAAjYQApbTptepaoHDAYYUonRksW4GEAcWyu7RoAfQB5LoArYBaYdo9cAmE-MkpqekY8aXEVOA3dObgfVABXMAqobQyECDgAHIQX4AJhBABoXqgWno4Hgzi1SH8EKRUF03iVbLo7nAFMJ%2BKBILA4E43k9bPYXv4LkFrmx2AAKACUKXQmGORGpgSuTHpBPA0HgpPJdgcZwCl2CLA4DMEKPwrKOXgAwvY8DAoG99tB%2BCy2Z4CMRztypXzCYKSWT9qKqcbJXSZXKyAr9RzVbp1ZrtVA4AAfOBkjJOaLAfS6xXsrxGiW03kcPhyqDAGBvKAOARCISiCRSISyWRAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6WJygM0sQBNaySgHMmAQ3yxoKdFETRoAe2iRwYAL4h1QA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
It's not possible to merge these overloads, so I expected no error
Actual Result
These overloads can be combined into one signature with an optional parameter. 11:3 - 11:27
Additional Info
No response
The text was updated successfully, but these errors were encountered: