-
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
set only property bug #4839
Comments
se #12 for more information. |
Is this really a duplicate? #12 is a suggestion for a read only modifier. I am not advocating that. I just think that if no getter is defined then the compiler should flag an error at compile time if you attempt to use it (like C# does). |
Write only property descriptors are perfectly valid JavaScript, therefore should be perfectly valid TypeScript. While it may not be a very useful programming paradigm, it is a legitimate one. |
Actually, I see what you want, you want #295 which is to throw when you attempt to access a write-only property (or a read-only property). As @RyanCavanaugh states, the type system doesn't currently support that differentiation. |
I see the problem. |
Yes, this issue is currently a plague to typescript. It should be addressed by typescript team. |
If you define a class that has a property which only has a setter, but not a getter, and then attempt to use the non-existent getter the code will compile, but the getter is undefined, leading to a crash when it is used. For example:
The above will compile, but crashes when reading obj.count.
Surely it would be better if this code did not compile.
The text was updated successfully, but these errors were encountered: