-
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
treating setters as properties rather than functions can be unsound #56922
Comments
I think those are 2 separate issues. My PR fixes |
Issue for |
I thought I think it would be best to have TypeScript represent prototype set() and/or get() literally - and to honor that behavior as literally as possible. (Obviously TypeScript accepts the set/get notation, but now it converts that a plain type (or is it a plain type with caveats?)). The best thing about the JS-literalist approach is that JS provides a solid reference for correct behavior.
Less need for documentation, less confusion for ts-users and for ts-developers. The counter argument to that is that 95% of all implementations are just using get() and set() as an alias for a plain type. However in those cases the user has to option to masquerade the get()/set() implementation with a plain type -
Just my two cents. This opinion is not part of the bug issue. |
There's one surprising aspect to this: A class with only a setter will provide an automatic getter that returns This is actually a source of unsoundness today: |
Am I correct that you are saying this about A class with only a setter which extends a class with a getter - ?
If that is true, then of course it is a mess and the Ecma group needs to get its act together and fix that, or least specify that that aspect is left to the implementer. However, looking at ECMA specs 15.4.2 Static Semantics: HasDirectSuper and 10.1.8.1 OrdinaryGet, I think it might actually specifiy returning From the former 15.4.2 Static Semantics: HasDirectSuper specification:
Note: From the latter 10.1.8.1 OrdinaryGet specification:
I think I have little experience interpreting the ECMA specs, so you should take my analysis with a pinch of salt. |
Yes, it is correct ECMAScript behavior that a class with only a setter returns
The only reason I'm pointing this out is because this behavior means that things aren't quite as simple as treating getters and setters as independent methods in the type system. |
This issue was foretold: People asked us for divergent get/set types, we pushed back and said "No that will be unsound in many ways that are impractical to seal up", people said "No that's okay, because it's no less unsound than the existing hole around property aliasing", and we said "Yeah good point", and now we're here. Properties in TypeScript have never been sound on writes, writeonly properties don't exist, and generally writeonly properties in JS are rare enough to not really merit further consideration. |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
setter union variance
is:issue in-title: setter (nothing relevant found)
is:issue in-title: setter union variance (nothing relevant found)
π Version & Regression Information
confirmed 4.3.5 ~ 5.3.2
β― Playground Link
https://www.typescriptlang.org/play?ssl=16&ssc=78&pln=15&pc=50#code/JYOwLgpgTgZghgYwgAgMoTJKAeAKgPmQG8AoZc5AZw2QAcoB7WgCgA8AuXASgG5kB6fsigBXcMAC2KaIyjJgMZK2QgGYeSGQATBhLihkuAHQkAviQQAbOJUrIAwgEYATPIm1LEKeDvpM0bCI4dkcAH2dTfFIKKhp6JjZ2IJDTUOSIrmiYigVkZgBCAG1HABpnAF0jUCsRLQhKNiM4Li5kMAALRgB3JR4yCnNzKxs7e2cAZjcPLwgfNAwsQODx8Mis8mp1eJYOZPHU9NNM-uz5RQLC5xLxyurLWvrG5taO7t6T5EGSGDEEMGAGJofs5mCJ2A4XMhQg4Jq11gIhO1oCgAETbFHyOxgKAQOCQLTISzAADWKA8+k022gYAAnh9BGd5Oousi2ji8RACUTScg4HRrAYfiA-gCQCViMFHKZxXtTMgugwRJYCQAjaRQWSUD4iIzbPgMyjtBhdOxhZyhcbi0TiKRUI0m5BiOowUCc8gMgCqADlUAB5b0AEW1usYtGQAF4JSl9UJaAxbMAVZ42p1jQjkN6-YHg9sI1GIn0Yjrc5HZTG6PHKInk68056ff6vUHzEKRYDkD9xqDwU5nHCc6G84dCzlzsXQ01w1O+-CYoIPl9gcwQBAer3mC0+gzyTSAOaMJ3IRVgWgiMAkBmFACiACUb+VwSir6wIAgz26AFJwABucFQCCgYBaHUAAxfRPC0dgMQvIRrzvB9kEmEhvhELsVzXFwN14GD+TgPcDxAAlj1Pc9L1ve9H2fV93wJL9f3-QDgOQMDgAgqDkBwuCKMdEMmExR1CIgF0VwJEggA
π» Code
π Actual behavior
π Expected behavior
Additional information about the issue
This supersedes issue #56894.
@Anadarist 's pull #56895 claims to fix #56894, it would be great if it fixed this issue also.
The text was updated successfully, but these errors were encountered: