-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Infer from union combined single signatures #58482
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
base: main
Are you sure you want to change the base?
Infer from union combined single signatures #58482
Conversation
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
@@ -12,8 +12,8 @@ declare const f: { (x: string): number, a: "" } & { a: number } | |||
> : ^^^^^^ | |||
|
|||
f() | |||
>f() : any | |||
> : ^^^ | |||
>f() : number |
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.
The function itself is still not callable here but that erroneous call shows a better return type now. This is caused by getSingleSignature
handling structured types now (an intersection in this very case)
@@ -280,5 +280,5 @@ export class L { | |||
set x(value: any); | |||
} | |||
export class M { | |||
set x(value: any); | |||
set x(value: boolean); |
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.
This comes from:
/**
* @param {number | boolean} v
*/
const mSetter1 = (v) => {}
/**
* @param {string | boolean} v
*/
const mSetter2 = (v) => {}
export class M {}
Object.defineProperty(M.prototype, "x", {
set: Math.random() ? mSetter1 : mSetter2
});
This feels like an improvement, those setter functions can be combined safely to a single signature with a boolean
parameter
@typescript-bot test it |
Hey @jakebailey, the results of running the DT tests are ready. There were interesting changes: Branch only errors:Package: webpack/v4
|
@jakebailey Here are the results of running the user tests comparing Something interesting changed - please have a look. Details
|
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos comparing Something interesting changed - please have a look. Details
|
I treat this as an experiment right now. I think the logic is sound and it makes sense. However, I wonder:
fixes #58468