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

Union of variant setters uses getter type for assignment #45376

Closed
thw0rted opened this issue Aug 9, 2021 · 0 comments Β· Fixed by #47674
Closed

Union of variant setters uses getter type for assignment #45376

thw0rted opened this issue Aug 9, 2021 · 0 comments Β· Fixed by #47674
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@thw0rted
Copy link

thw0rted commented Aug 9, 2021

Bug Report

πŸ”Ž Search Terms

variant accessor setter union

πŸ•— Version & Regression Information

  • I was unable to test this on prior versions because: variant accessors only landed in 4.3

⏯ Playground Link

Example from below

πŸ’» Code

class One {
  get prop(): string { return ""; }
  set prop(s: string | number) { }
}

class Two {
  get prop(): string { return ""; }
  set prop(s: string | number) { }
}

declare const u1: One|Two;
u1.prop = 42; //Type 'number' is not assignable to type 'string'.(2322)

I didn't include it in the playground, but behavior is the same for class or interface.

πŸ™ Actual behavior

Assignment of number is flagged as an error, even though both sides of the union allow assignment of a number.

πŸ™‚ Expected behavior

Assignment should not be flagged.


Originally reported by @ws93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants