-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Make getter-only member non-assignable to getter+setter member #27538
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
Comments
Also, I tried to implement (by modifying interface I {
method(): void;
}
class C implements I {
readonly method = () => {};
}
function doAction(v: I) {}
doAction(new C()); // Works in 3.2.0-dev, but would've been broken
// if I'd implemented this feature for `readonly` attributes as well. |
Duplicate of #8496 |
@Andy-MS from my perspective, this's a kind of duplicate. Because it would be great to fix both issues (getter+setter and readonly). But, due to backward compatibility reasons and due to What do you think? |
These are the same problem though -- TypeScript considers a |
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed for automatic house-keeping purposes. |
Search Terms
getter, setter
Suggestion
Prevent types with getter-only attributes (read-only behavior) to be assignable to types with setter attributes (read-write) behavior. This pretty suits the structural type system.
Use Cases
In 3.2.0-dev we're able to assign a read-only instance to a read-write typed variable and then try to assign those read-only attributes. However, this code will raise an error in the strict-mode runtime.
So, it would be better to catch this error during the compile-time.
Examples
Well, the proposal it to fail on the following assignment:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: