-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Getting a setter-only property is typed as the setter's parameter's type instead of undefined #60954
Comments
That sounds good. Except that when said variable is a #private, it throws an exception instead of returning undefined... but that's probably not the same issue. Maybe it could be typed as |
Implicitly making a |
You may believe it to be suspiscious, but it's a practice that's fully and explicitly supported by MDN (I don't have the courage to read ECMA specs but save from that, I guess it's the best source of authority in the matter). It's more common to have a getter-only than a setter-only property, sure, but still it is also useful on its own. I use it as a seed-setter for RNG objects, and using a setter property rather than a setter method allows several generators to be given the same seed at the same time without having to define a variable. Sure, it's not the most crucial feature I could think off, but if it's explicitly part of the standard, it's not ours to second-guess. And you could also concievably rely on that to make contravariant property types... though I did not encounter it, it's theoretically a valid use-case. And finally, could you give an example of code where this would be a breaking change ? |
Ok, fair point. But as per the examples above, I still think it's a useful feature. |
π Search Terms
setter only
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.7.3#code/MYewdgzgLgBANgQzAcwK4OQUxgXhgbwCgYYJNZhUAnKzMKACjAQFtMAuUqKgSxQEoCxEjCgALHhAB0cEMikAHVBDFNWmfgG5hAXwA0w2ck4BtALowEELrxTmDO7YUQp0WKZRp1YeAEQAxACVfJ1BIClx4JDQMTA9qWnptIA
π» Code
π Actual behavior
Variable
c
is said to be of typestring
.π Expected behavior
As clearly stated here, it should be
undefined
.Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: