-
Notifications
You must be signed in to change notification settings - Fork 57
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
Cannot assign to read only property of object #57
Comments
This seems like an issue with the |
No, I think its not. Simple example of reproduction without typeorm: function dec(id) {
return (target, property, descriptor) => console.log("executed", id);
}
export class Category {
@dec()
id = 0;
@dec()
name;
}
const category = new Category();
category.id = 1;
category.name = "hello"; produces: /Users/pleerock/www/opensource/typeorm/babel-example/dist/index.js:79
category.name = "hello";
^
TypeError: Cannot assign to read only property 'name' of object '#<Category>'
at Object.<anonymous> (/Users/pleerock/www/opensource/typeorm/babel-example/dist/index.js:79:15) Note that |
Would you be able to put together a simple example repo? Dropping that into a repo with
logs
for me, so something else may be interfering? |
why do you put |
Here is my configuration: {
"presets": [
"es2015"
],
"plugins": [
"transform-decorators-legacy",
"transform-class-properties"
]
} |
You are right, I tried both to make sure and then copy-pasted the wrong one. I am able to reproduce with |
The problem originates from this check: index.js (LINE 54) I'm not familiar enough with the code to be sure if it can be safely removed. |
Yeah that's definitely the line. That was carried over from Babel 5.x here: https://github.com/babel/babel/blob/5.x/packages/babel/src/transformation/templates/helper-create-decorated-class.js#L15 and the same bug reproduces in Babel 5 too. |
Any solutions? |
Is this solved? |
I have such error:
Cannot assign to read only property 'name' of object '#<Category>'
when I use non initialized properties decorated with decorators and then trying to assign values to these properties.Solution is to do it this way:
Which is ugly. I guess the reason is that it does not make descriptor writable. Is there any better solution for this problem?
The text was updated successfully, but these errors were encountered: