TypeError: Issues in constructor
See original GitHub issueIssue type:
[ ] question [x ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x ] postgres
[ ] sqlite
[ ] sqljs
[ ] websql
TypeORM version:
[x ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
- Clone this repo https://github.com/cedrickmandocdoc/typeorm-bug
- Create PG Database with name test, edit what roles you will used
- Install packages
- Compile run tsc
- Run index.js Result:
- You will notice that there is a TypeError.
I guess this is because of the constructor. I believe there is workaround here, but I want to preserve also the types and have strictnullchecks set to true. Though if I edit the constructor parameters and isolate it one by one. It will works. I just want to know why this sample repo didn’t work. I guess this is a bug.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >Resolving TypeError: "X" is Not a Constructor in JavaScript
JavaScript "TypeError: "x" is not a constructor" errors occur when invalid objects or a variable is erroneously used as a constructor.
Read more >TypeError() constructor - JavaScript - UDN Web Docs
The TypeError() constructor creates a new error when an operation could not be performed, typically (but not exclusively) when a value is not...
Read more >Javascript "Not a Constructor" Exception while creating objects
In chrome, at least, there seem to be several variations of non-function/non-ctor related messages. Your example gives "TypeError: object is not a function." ......
Read more >TypeError: "x" is not a constructor - CodeProject Reference
Invalid cases ; var Car = 1 ; new Car(); // ; new Math(); // ; new Symbol(); // ; TypeError: Symbol is...
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 Free
Top 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
You have two issues.
create
does not save entity in the database and it does not return you a promise, and it does not accepts constructor arguments, you are using it completely wrong (I guess you are confusing methods of sequelize library, create in typeorm serves different purpose). Your correct code for saving entity is:Second, your entity constructor arguments must be optional, its a requirement, since when loading entities from the database ORM creates instances of the classes, and it does not aware of your constructor arguments and what it shall provide there. How it should be in your code:
That’s exactly what this feature is created for, so I think it’s using it wisely. There are no “hacks” here, in fact, your solution is the hack as it actually translates into the javascript output. My solution keeps the js code clean and simple.