-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Add new type: Mutable #27
Comments
Interesting, will figure out a bit later, have a lot on my plate right now. |
I'm not sure about this one, like is it something really useful? |
I once used it in an Angular app. But in some presentational document I had to mutate an object for two-way binding purposes. So I derived the original type with Since then I had refactored that part and it no longer exists. That was the only occurrence. So yes it's pretty rare. |
const copy = Object.assign({}, this.state); // copy the state of react
copy.options = []; // raise error "TS2540: Cannot assign to 'options' because it is a read-only property"
this.setState({...copy}) It is fixed as follows: const copy: Mutable<IState> = Object.assign({}, this.state); // copy the state of react
copy.options = []; // not raise error here now
this.setState({...copy}) or const copy = Object.assign<{}, IState>({}, this.state); There may be other scenarios but yes, it are not usual cases. |
@emilgpa this can be fixed by just |
@levenleven This is not about whether there is another way to clone an object but that there may be a scenario where you need to be able to mutate an object. |
Ok let's include this type, I agree with the @emilgpa argument that there might be some cases where you would want to reverse operation of DeepReadonly helper or clone immutable object to mutate it. Accepting PRs. |
@IssueHunt has funded $20.00 to this issue.
|
Resolves: piotrwitek#27
Resolves: piotrwitek#27
Resolves: piotrwitek#27
Resolves: piotrwitek#27
@piotrwitek has rewarded $14.00 to @dosentmatter. See it on IssueHunt
|
Would be lovely to have |
I think that there are not a type for mutable object
IssueHunt Summary
Backers (Total: $20.00)
Submitted pull Requests
Mutable
typeTips
IssueHunt has been backed by the following sponsors. Become a sponsor
The text was updated successfully, but these errors were encountered: