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

Allow getter and setter types to be unrelated #53417

Merged
merged 2 commits into from
Mar 30, 2023

Conversation

andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Mar 21, 2023

Fixes #43662

The one thing to note/discuss here is that to create unrelated accessors, both the getter and setter must have explicit annotations, because the setter’s type annotation will be used for an unannotated getter return type:

// Error:
const unannotatedGetter = {
  get p() {
    return 0;
//  ^^^^^^^^ Type 'number' is not assignable to type 'string'
  },
  set p(value: string) {
    // ...
  },
};

// Ok:
const bothAnnotated = {
  get p(): number {
    return 0;
  },
  set p(value: string) {
    // ...
  }
};

I think this is probably better than making it too easy to accidentally create unrelated accessor types, but perhaps it’s not obvious from the error message that unrelated accessor types are possible.

Copy link
Member

@RyanCavanaugh RyanCavanaugh left a comment

Choose a reason for hiding this comment

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

LGTM implementation-wise; let's double-check that we want to do this at the next meeting

@sandersn
Copy link
Member

:shipit:

@andrewbranch andrewbranch merged commit 5586727 into microsoft:main Mar 30, 2023
@andrewbranch andrewbranch deleted the feature/43662 branch March 30, 2023 15:51
@shellscape
Copy link

@andrewbranch which version did this land in? having trouble finding it in changelogs

@jakebailey
Copy link
Member

5.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow setter type to be incompatible with the getter type
7 participants