-
Notifications
You must be signed in to change notification settings - Fork 12.4k
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
Are there some good approach to remove 'readonly' restriction templorary from fields? #6717
Comments
I'd propose using a public |
I also thought the following usecase, so its escape hatch is like a C++'s class B {
// I'd not like to modify this field only in a constructor/destructor
private b: SomeLargeObject;
constructor(b: SomeLargeObject) {
this.b = SomeLargeObject;
}
bar(): void {
var blahblah = createSomeLargeObject();
this.b = blahblah; // I'd like to ban this operation.
}
destroy(): void {
this.b = null; // I'd like to allow this.
}
} |
@saneyuki This is allowed in public destroy() {
delete this.scheduler;
delete this.stream;
...
} |
environment
typescript@1.9.0-dev.20160128
description
relate? : #6532
In some case (e.g. to development framework), I'd like to do a destruct operation for the members which is restricted as
readonly
to release a some large object explicitly. But it would be the compile error if I assign a value to the restricted member in a non-constructor()
method.I know we can avoid this error if casting
this
toany
type, but it would not be a type safe. In other approach, we can also do it if we define a "mutable" interface and cast to it, but it would be wordy....Are there some good approach to remove 'readonly' restriction templorary?
The text was updated successfully, but these errors were encountered: