Skip to content
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

Andarist fix union intersection setters #56915

Conversation

craigphicks
Copy link

@craigphicks craigphicks commented Dec 31, 2023

This draft was created only to analyze a couple more tests files in the context of pull #56895

Fixes #

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 31, 2023
x.d = id();
// ^ const id: <1 | 2 | 3>() => 1 | 2 | 3 (5.3.2)
// ^ const id: <2>() => 2 (expecting, if a setter was treated as a function)
x.r;
Copy link
Author

Choose a reason for hiding this comment

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

Was expecting pull #56895 to change this behavior, because therein it say it fixes #5689. But no change occurred as far as I can see.

Copy link
Contributor

Choose a reason for hiding this comment

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

Getters are treated like properties so a union of getters returns the union of their return types. I think this just works as expected. Even if we treat them as functions - it still all checks out, return types are unionified:

declare const fn: (() => 1 | 2) | (() => 2 | 3)
const result = fn()
//    ^? const result: 1 | 2 | 3

Copy link
Author

Choose a reason for hiding this comment

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

My comment and the subject of #56894 is setters. The point of the result diff is that valid domain has not narrowed by your fix. For more clarity see #56922.

function f4(x: {set d(a:1|2); get r():1|2} | {set d(a:2|3); get r():2|3} ){
//           ^ (parameter) x: { d: 1 | 2; readonly r: 1 | 2; } | { d: 2 | 3; readonly r: 2 | 3; }
    x.d = id();
//        ^ const id: <1 | 2 | 3>() => 1 | 2 | 3      (5.3.2)
//        ^ const id: <2>() => 2      (expecting, if a setter was treated as a function)

@jakebailey
Copy link
Member

#56895 is closed, so I'm going to close this draft too.

@jakebailey jakebailey closed this Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants