Cannot assign to read only property of object
See original GitHub issueI 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.
import {Entity, PrimaryColumn, Column} from "typeorm";
@Entity()
export class Category {
@PrimaryColumn("int", { generated: true })
id;
@Column("string")
name;
}
Solution is to do it this way:
import {Entity, PrimaryColumn, Column} from "typeorm";
@Entity()
export class Category {
@PrimaryColumn("int", { generated: true })
id = undefined;
@Column("string")
name = "";
}
Which is ugly. I guess the reason is that it does not make descriptor writable. Is there any better solution for this problem?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Uncaught TypeError: Cannot assign to read only property
When you use Object.defineProperties , by default writable is set to false , so _year and edition are actually read only properties.
Read more >[Cannot assign to read only property '<field_name>' of object ...
This type of error(Cannot assign to read-only property) generally occurs on update of public property @api decorator variable value.
Read more >TypeError: "x" is read-only - JavaScript - MDN Web Docs
The JavaScript strict mode-only exception "is read-only" occurs when a global variable or object property that was assigned to is a read-only property....
Read more >JavaScript Cannot Assign to Read-only Property of Object in ...
1. <!DOCTYPE html> ; 2. <html lang="en"> ; 3. <head> ; 4. <meta charset="utf-8"> ; 5. <title>JavaScript Cannot Assign to Read-only Property of...
Read more >TypeError: Cannot assign to read-only property "parent"
TypeError : Cannot assign to read-only property "parent" ... The code in question is: var text = newElement(Element.STAFF_TEXT); text.parent = ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You are right, I tried both to make sure and then copy-pasted the wrong one.
I am able to reproduce with
es2015
. Thanks for the info.Is this solved?